2011-05-09 7 views
0

주요 활동 :확장 목록보기

public class ListActivityEx extends Activity { 
/** Called when the activity is first created. */ 
LayoutInflater inflate; 
ExpandableListAdapter adapter; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    adapter = new MyCustomExpand(this); 
    ExpandableListView expand = (ExpandableListView) findViewById(R.id.expandableListView_profile); 
    expand.setAdapter(adapter); 

} 

} 

어댑터 클래스 :

public class MyCustomExpand extends BaseExpandableListAdapter { 
LayoutInflater infalInflater; 
private String[] groups = { "Test1", "Test2", "Test3" }; 

private String[][] children = { 

{ "neelinfo", "MobileApp", "HYD" }, 

{ "rajesh", "palepu", "narasimha" }, 

{ "Android", "iphone", "J2ME" } }; 

// Add these lines to your code 
private Context context; 

public MyCustomExpand(Context context) { 
    this.context = context; 
} 


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 View getChildView(int groupPosition, int childPosition, boolean isLastChild, 
     View convertView, ViewGroup parent) { 

    if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater) context 
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.child_row, null); 
    } 

    TextView textView = (TextView) convertView.findViewById(R.id.childname3); 
    textView.setText(getChild(groupPosition, childPosition).toString()); 
    return convertView; 
} 
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) { 
    ViewHolder holder = null; 
    if (convertView == null) { 
     switch (groupPosition) { 
     case 0: 

      holder = new ViewHolder(); 
      infalInflater = (LayoutInflater) context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.group_row, null, 
        false); 
      holder.textView = (TextView) convertView 
        .findViewById(R.id.childname); 
      Log.d("heading", getGroup(groupPosition).toString()); 
      holder.textView.setText(getGroup(groupPosition).toString()); 

      break; 
     case 1: 
      infalInflater = (LayoutInflater) context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.group_row2, null, 
        false); 
      holder = new ViewHolder(); 
      holder.textView = (TextView) convertView 
        .findViewById(R.id.childname11); 
      // holder.textView.setText(getGroup(groupPosition).toString()); 
      Log.d("heading", getGroup(groupPosition).toString()); 

      holder.textView.setText(getGroup(groupPosition).toString()); 
     case 2: 
      infalInflater = (LayoutInflater) context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.group_row2, null, 
        false); 
      holder = new ViewHolder(); 
      holder.textView = (TextView) convertView 
        .findViewById(R.id.childname11); 
      // holder.textView.setText(getGroup(groupPosition).toString()); 
      Log.d("heading", getGroup(groupPosition).toString()); 
      holder.textView.setText(getGroup(groupPosition).toString()); 
     } 
    } 
    return convertView; 
} 

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

public boolean hasStableIds() { 
    return true; 
} 

static class ViewHolder { 
    TextView textView; 
} 

} 
+0

나는 진실성을 얻고있다 ifr 나는 그룹 위치를 클릭한다 1.i. 제 2 그룹의 chaild를 얻고있다 .... 나는 왜 그런지 모르겠다 ?? 아무도 제발 나를 도울 수 있습니까 ??? 나는 Custon 필요 Android 확장 가능 목록 – rajesh

답변

0

당신이 case 1:break이 없기 때문입니다. 및 '사례 2'