2012-05-22 80 views
0

我在Android上使用ExpandableListView。我必須通過點擊孩子來調用不同的活動。每個孩子都必須指導我參加新的活動。請告訴我,我該怎麼做。來自onChildClick的Statrt newActivity expandableListView

我的代碼是有點像:

list.setOnChildClickListener(new OnChildClickListener() { 
    public boolean onChildClick(ExpandableListView parent, View v, 
     int groupPosition, int childPosition, long id) { 
     // TODO Auto-generated method stub 
     ExpandableListAdapter adap = parent.getExpandableListAdapter(); 
     int gp = (int) adap.getGroupId(groupPosition); 
     int cp = (int) adap.getChildId(groupPosition, childPosition); 
     if (gp == 0) { 
      switch (cp) { 
      case 0: 
       Intent intent = new Intent(getApplicationContext(), 
        Test11.class); 
        break; 
       case 1: 
       Intent intent = new Intent(getApplicationContext(), 
          Test12.class); 
       } 
      } else if (gp == 1) { 
       switch (cp) { 
       case 0: 
       Intent intent = new Intent(getApplicationContext(), 
          Test21.class); 
        break; 
       case 1: 
       Intent intent = new Intent(getApplicationContext(), 
          Test22.class); 
        break; 
       } 
      } 

      return true; 
     } 

    }); 
+0

什麼是你現在所面臨的困難? –

+0

當我點擊子節點應用程序意外停止 –

回答

0

也許我認爲你缺少startActivity(),

list.setOnChildClickListener(new OnChildClickListener() { 
    public boolean onChildClick(ExpandableListView parent, View v, 
     int groupPosition, int childPosition, long id) { 
     // TODO Auto-generated method stub 
     ExpandableListAdapter adap = parent.getExpandableListAdapter(); 
     int gp = (int) adap.getGroupId(groupPosition); 
     int cp = (int) adap.getChildId(groupPosition, childPosition); 
     if (gp == 0) { 
      switch (cp) { 
      case 0: 
       Intent intent = new Intent(getApplicationContext(), 
        Test11.class); 
       startActivity(intent); 
        break; 
       case 1: 
       Intent intent = new Intent(getApplicationContext(), 
          Test12.class); 
       startActivity(intent); 
       } 
      } else if (gp == 1) { 
       switch (cp) { 
       case 0: 
       Intent intent = new Intent(getApplicationContext(), 
          Test21.class); 
       startActivity(intent); 
        break; 
       case 1: 
       Intent intent = new Intent(getApplicationContext(), 
          Test22.class); 
       startActivity(intent); 
        break; 
       } 
      } 

      return true; 
     } 

    }); 
+0

我試過了,但它給錯誤...請幫我。 –

+0

是的。什麼是錯誤? –

+0

錯誤是「應用程序ExpandableView(包名稱)意外停止,請重試。」 –

相關問題