2011-06-24 12 views
0

私は私のAndroidアプリに問題がある、私は検索が、答えを見つけることができない、私はこのコードを持っている:AndroidのListViewコントロール

public class Matematika extends ListActivity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     String[] mStrings = new String[]{"Mother", "Sister", "Brother"}; 

     // Create an ArrayAdapter, that will actually make the Strings above appear in the ListView 
     this.setListAdapter(new ArrayAdapter<String>(this, 
     android.R.layout.simple_list_item_1, mStrings)); 
    } 
} 

を、私はこの例のようにしたい:私は上をクリックします母と次に行きたいListActivity(それが本当ならそれを意図した新しいアクティビティ)、ListActivity、別のオプションがあります....

ありがとう。

答えて

1
@Override 
    protected void onListItemClick(ListView lv, View v, int position, long id) { 
     super.onListItemClick(lv, v, position, id); 
     try { 
      switch (position) { 
      case 0: //Mother 
        //Launch MotherActivity 
        Intent motherIntent = new Intent(this, MotherListActivity.class); 
        startActivity(motherIntent); 
       break; 
      case 1: //Sister 
       //Call SisterActivity 
       Intent sisterIntent = new Intent(this, SisterListActivity.class); 
       startActivity(sisterIntent); 
       break; 
      case 2: //Brother 
       Intent brotherIntent = new Intent(this, BrotherListActivity.class); 
       startActivity(eventsIntent); 
       break; 
      } 
     } catch (Exception e) { 
      Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); 
     } 
    } 
関連する問題