2011-09-03 2 views
0

내 ExpandableListActivity의 항목을 나열하도록 OnClickListener를 설정하는 데 문제가 있습니다. 코드 구조는 다음 예와 일치 :Android 확장형 목록 - OnClickListener

내가 리스너를 설정할 수있어 일단
ExpandableListAdapter mAdapter; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // Assign the adapter 
    mAdapter = new MyExpandableListAdapter(); 
    setListAdapter(mAdapter); 
} 

public class MyExpandableListAdapter extends BaseExpandableListAdapter { 
    private String[] groups = { "foo", "bar"}; 
    private String[][] children = { 
       {"fooA", "barA"}, 
     {"fooB", "barB"} 
      }; 

    public Object getChild(int groupPosition, int childPosition) { 
     return children[groupPosition][childPosition]; 
    } 

    public long getChildId(int groupPosition, int childPosition) { 
     return childPosition; 
    } 

    public int getChildrenCount(int groupPosition) { 
     return children[groupPosition].length; 
    } 

    public TextView getGenericView() { 
     // Layout parameters for the ExpandableListView 
     AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
       ViewGroup.LayoutParams.MATCH_PARENT, 64); 

     TextView textView = new TextView(Calculations.this); 
     textView.setLayoutParams(lp); 
     // Center the text vertically 
     textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); 
     // Set the text starting position 
     textView.setPadding(64, 0, 0, 0); 
     return textView; 
    } 

     public View getChildView(int groupPosition, int childPosition, boolean isLastChild, 
      View convertView, ViewGroup parent) { 
     TextView textView = getGenericView(); 
     textView.setText(getChild(groupPosition, childPosition).toString()); 
     textView.setPadding(98, 0, 0, 0); 
     return textView; 
    } 

    public Object getGroup(int groupPosition) { 
     return groups[groupPosition]; 
    } 

    public int getGroupCount() { 
     return groups.length; 
    } 

    public long getGroupId(int groupPosition) { 
     return groupPosition; 
    } 

    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, 
      ViewGroup parent) { 
     TextView textView = getGenericView(); 
     textView.setText(getGroup(groupPosition).toString()); 
     return textView; 
    } 

    public boolean isChildSelectable(int groupPosition, int childPosition) { 
     return true; 
    } 

    public boolean hasStableIds() { 
     return true; 
    } 
} 

, 내가 가장 가능성 같은 것을 할 수 있습니다 :

// Listener 
{ 
    switch(groupPosition) { 
    case 0: 
     switch(childPosition) { 
     case 0: 
      selected = 00; 
      return true; 
     } 
    } 
}// Close listener 

아니에요 경우 알려주세요 충분히 명확하다.

+0

어디에서 수신기를 연결 하시겠습니까? ExpandableList에있는 그룹의 하위 사용자에게? – momo

답변

0

활동 내에서 onChildClick()을 무시해야합니다.

부울 onChildClick (ExpandableListView 부모,보기 V, INT의 groupPosition, INT의 childPosition, 긴 ID는) 아이가 클릭되었을 때 콜백을 수신하는,이 메소드를 오버라이드 (override) .

+0

도움이 되셨습니까? ... – Ronnie