I have following goal: From a list in main activity that extends ListActivity, I want to start other activities.
This is the code of the main activity:
public class SelectionWidgetsExampleActivity extends ListActivity {
private Class[] demos = {ListViewDemo.class, ChecklistDemo.class};
private ArrayAdapter<Class> aa;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
aa = new ArrayAdapter<Class>(this, android.R.layout.simple_list_item_1, demos);
setListAdapter(aa);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent intent = new Intent(this, demos[position]);
startActivity(intent);
}
}
My question is
How would you solve the issue of having list of classes to be executed outside the code of the main activity?
My first idea was to put it into xml resource file as string array. I can then easily create array of Strings from the resource, but don't know how to convert the string to the class - I need something like:
SomeJavaClass.getMeClassFromString(demos[position])