さて、私はAndroidに比較的慣れていないので、メニュー項目の名前に問題があります。これをできる限り説明しようと思います。
public class Menu extends ListActivity{
//Should be named the same as the Class itself
String classes[] = { "example1", "example2", "example3", "example4", "example5"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.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
String classPosition = classes[position];
super.onListItemClick(l, v, position, id);
try{
Class testClass = Class.forName("com.Test." + classPosition);
Intent testIntent = new Intent(Menu.this, testClass);
startActivity(testIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
私は現在このメソッドを使用していますが、私が抱えている問題は、メニューに表示される名前が、それが機能するためにクラス名と同じでなければならないということです。「Test」という名前のアクティビティを呼び出したい場合、表示される名前は「Test」である必要があります。もっと時間があれば、これは理解できると思いますが、私にはわかりません。どんな助けでも大歓迎です。ありがとう。