代码:
class MainActivity extends AppCompatActivity {
private String[] groups={"好友","同学"};
private String[][] childs={
{"Tom","Jerry","Jeck"},{"XY","WX","YH"}};
ExpandableListView el;
MyExpandableAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
el= (ExpandableListView) findViewById(R.id.expand_listview);
adapter=new MyExpandableAdapter(getBaseContext(),groups,childs);
el.setAdapter(adapter);
el.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Toast.makeText(MainActivity.this, "当前位置"+childs[groupPosition][childPosition], Toast.LENGTH_SHORT).show();
return true;
}
});
}
}
**********************************************************************
public class MyExpandableAdapter extends BaseExpandableListAdapter {
private String[] groups;
private String[][] childs;
Context m