我主要讲述的是用listview实现、模仿qq好友分组点击收缩、扩展功能
这个是对listview的拓展,用法比较相似,还是需要一个适配器
MainActivity
public class MainActivity extends Activity {
private ExpandableListView ex;
//声明一个ExpandableListView 用的数据源
//组
private List<ExpandInfo> list=new ArrayList<ExpandInfo>();
private MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ex=(ExpandableListView) findViewById(R.id.expand);
//初始化数据源
initList();
adapter=new MyAdapter(MainActivity.this, list);
ex.setAdapter(adapter);
//ExpandableListView子条目点击事件
ex.setOnChildClickListener(new OnChildClickListener() {
@SuppressLint("WrongConstant")
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
String str=((ChildInfo)adapter.getChild(groupPosition, childPosition)).NickName;
Toast.makeText(MainActivity.this, str, 0).show();
return false;
}
});
}
//初始化数据源
private void initList() {
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList("杨波", "鲁育铭", "梁天勉","刘康","赵明","杨波", "鲁育铭", "梁天勉","刘康","赵明"));
ArrayList<String> arrayList_friend = n