标签:
package com.example.dajj;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
public class MainActivity extends Activity {
private ExpandableListView ev;
String[] name = new String[] { "你好", "我好", "dajiahao", "他好" };
String[][] names = new String[][] { { "他后", "爱的", "爱的" },
{ "他后", "爱的", "爱的" }, { "他后", "爱的", "爱的" }, { "他后", "爱的", "爱的" } };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ev = (ExpandableListView) findViewById(R.id.ev);
ev.setAdapter(new BaseExpandableListAdapter() {
@Override
public boolean isChildSelectable(int groupPosition,
int childPosition) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View view = View.inflate(MainActivity.this,
android.R.layout.simple_list_item_1, null);
TextView text = (TextView) view
.findViewById(android.R.id.text1);
text.setText(name[groupPosition]);
return view;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return name.length;
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return names[groupPosition].length;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = View.inflate(MainActivity.this,
android.R.layout.simple_list_item_1, null);
TextView text = (TextView) view
.findViewById(android.R.id.text1);
text.setText(names[groupPosition][childPosition]);
return view;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public Object getChild(int arg0, int arg1) {
// TODO Auto-generated method stub
return arg1;
}
});
}
}
标签:
原文地址:http://www.cnblogs.com/ydlzj/p/5354953.html