2011-06-24 40 views
0

我有問題,我的Android應用程序,我搜查,但找不到答案,我有這樣的代碼:Android的ListView控件到下一個活動的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(); 
     } 
    } 
相關問題