Is it possible to create a calendar in Android Eclipse?

1

I need to create a "private" contact calendar (not the phone's own API).

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

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

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

    
asked by anonymous 13.11.2014 / 03:35

1 answer

2

Yes, this is possible, I see 2 ways to do it.

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

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

This code will cause your "A" button to go to the activity of contact list 1.

1st way

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

FileWriter and BufferedWriter implementation example

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());
    } 
} 

FileReader and BufferedReader implementation example

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 type File that has the path of the file to be written and read.

2nd way

If you feel comfortable already doing a little more elaborate programming, it's worthwhile to use SQLite and have a much better organization of your records, so you can do the same things that 1º maneira does, a more elegant and better way.

    
13.11.2014 / 12:17