Is it possible to create an agenda on Android Eclipse?

Asked

Viewed 300 times

1

I need to create a "private" contacts schedule (other than the mobile API itself).

For example: I have the BUTTON (A) and BUTTON (B); AGENDA (A) and AGENDA (B);

  • When the user clicks the BUTTON (A), it will be sent to AGENDA Activity (A);
  • When the user clicks the button (B), it will be sent to AGENDA Activity (B);

In this case, each contact in each calendar would be added by the user himself. But then, would this be possible? If yes, what would be the "correct name" of this feature?

1 answer

2


Yes, that’s possible, I see 2 ways to do it.

The basics are 2 buttons like yourself said, and each button will load a different list, the code to change from Activity would be basically the following:

public void BotaoA_Click(View v)
{
    Intent lista1 = new Intent(this, Lista1.class);
    startActivity(lista1);
}

This code will make it so that when your "A" button is clicked, it goes to the Activity of the 1 contacts list.

first way

Because I am learning, I believe that at first, to make this list, the best would be to create a file. txt, at the root of your phone containing the basic information you want, example: Name, Phone, Mobile and so on. By clicking add contact it adds in this file with a basic tab using the classes FileWriter and BufferedWriter. And from this file . txt you make a ListView reading the file you created with the classes FileReader and BufferedReader to show your contacts, and by clicking on the item, it opens the contact with more details.

Example of the Filewriter and Bufferedwriter implementation

public void writeLog(String writeIt)
{ 
    try { 
        FileWriter fWriter = new FileWriter(file, true);
        BufferedWriter bufferedWriter = new BufferedWriter(fWriter);
        bufferedWriter.append(writeIt);
        bufferedWriter.newLine();
        bufferedWriter.flush();
        bufferedWriter.close();
    } catch (Exception e) {
        Log.e("Error(Log)", e.toString());
    } 
} 

Example of the implementation of Filereader and Bufferedreader

public String[] readFile()
{ 
    ArrayList<String> lista = new ArrayList<String>();
    String[] vStrings = null;
    if (file.exists()) {
        FileReader fileReader;
        BufferedReader bufferedReader;
        String lineString;
        int count = 0;
        try { 
            fileReader = new FileReader(file);
            bufferedReader = new BufferedReader(fileReader);
            while ((lineString = bufferedReader.readLine()) != null) {
                lista.add(lineString);
            } 
            fileReader.close();
            bufferedReader.close();
            vStrings = new String[lista.size()];
            vStrings = lista.toArray(vStrings);
        } catch (Exception e) {
            Log.e("Error(readFile())", e.toString());
        } 
    } 
    return vStrings;
} 

Where the variable file is an object of the type File who has the path of the file to be written and read.

second way

If you feel already comfortable to do a little more elaborate programming, it is worth it to use the SQLite and have a much better organization of their records, thus being able to do the same things as the 1º maneira makes, in a more elegant and better way.

  • Thank you so much for your help! But then, as I am starting now, I will try to do the first method and then try to use the 2nd method with Sqlite. I don’t have much knowledge about B.D, but I will try and study this method. Thanks, hugs!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.