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.