first I am a programming noob and I wanted to do something like taking the user when he/she select Clear_data and it will take the person to Clear_data activity.
I am running in to a problem with try and catch, as I am still a bit lost in general programming. As I testing it when I select the first choice which is Text_Colour and it opens up the Clear_data activity instead of Text_Colour.
Here is the code:
public class Settings extends ListActivity {
String classes[] = { "Text_Colour", "Clear_data", "Contact Developer" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Settings.this, android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String colours = classes[0];
String cdata = classes[1];
try {
Class Class1 = Class.forName("com.example.test1." + colours);
Intent intent1 = new Intent(Settings.this, Class1);
startActivity(intent1);
}catch(ClassNotFoundException e) {
e.printStackTrace();
}
try {
Class Class2 = Class.forName("com.example.test1." + cdata);
Intent intent2 = new Intent(Settings.this, Class2);
startActivity(intent2);
}
catch(ClassNotFoundException d) {
d.printStackTrace();
}
}
Thanks for your time guys.
You sholud probably add a switch operator like this: