私はAndroidアプリに取り組んでいますが、問題が発生していListActivity
ます。Activity
リスト内のどの項目をクリックするかによって、スタートを変えたいと思います。
リストを作成しsetListAdapter
てJavaで参照しましたが、で参照する方法がわかりませんOnListItemClick
。リスト内の位置を参照する必要があると思います。
とActivity
を使用してButtons
、を設定し、各に対してaを指定してステートメントをOnClickListener
使用できます。に相当するものは何ですか?switch
case
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);
}
}