我正在开发一个 android 应用程序,但在使用ListActivity. Activity根据单击列表中的哪个项目,我想有一个不同的开始。
我制作了一个列表并setListAdapter在 java 中引用了它,但我不确定如何在OnListItemClick. 我假设我需要引用列表中的位置。
使用Activityand Buttons,我可以设置OnClickListenerand 使用switch带有casefor each的语句Button。什么是等价物ListActivity?
这是我的代码:
public class Options extends ListActivity implements {
String myHistory[]= { "Item 1", "Item 2", "Item 3" };
//---Set ListView---
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String> ( Options.this,
android.R.layout.simple_list_item_1, myHistory)));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
//--if click position 1, do below
//--Intent a = new Intent("show Item 1's corresponding page");
//--startActivity(a);
//--if click item in position 2, do below
//--Intent b = new Intent("show Item 2's corresponding page");
//--startActivity(b);
//--if click item in position 3, do below
//--Intent c = new Intent("show Item 3's corresponding page");
//--startActivity(c);
}
}