首先要先导一个modlue,刷新的。
然后布局中:注意:
<com.handmark.pulltorefresh.library.PullToRefreshExpandableListView android:id="@+id/list_expand" android:layout_width="match_parent" android:layout_height="match_parent"> </com.handmark.pulltorefresh.library.PullToRefreshExpandableListView>在代码中:
private PullToRefreshExpandableListView list_expand; private String[] str; private String[][] strr; private Handler handler=new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initview(); getserdata(); list_expand.setMode(PullToRefreshBase.Mode.BOTH); list_expand.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ExpandableListView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<ExpandableListView> refreshView) { handler.postDelayed(new Runnable() { @Override public void run() { list_expand.onRefreshComplete(); } },2000); } @Override public void onPullUpToRefresh(PullToRefreshBase<ExpandableListView> refreshView) { handler.postDelayed(new Runnable() { @Override public void run() { list_expand.onRefreshComplete(); } },2000); } }); myadpter m1=new myadpter(); list_expand.getRefreshableView().setAdapter(m1); } private void initview() { list_expand = (PullToRefreshExpandableListView) findViewById(R.id.list_expand); } public void getserdata() { str = new String[]{"三国","水浒","西游","红楼"}; strr = new String[][]{{"张飞","关羽","刘备"},{"宋江","李逵","林冲"},{"孙悟空","唐僧","猪八戒","沙和尚"},{"贾宝玉","林黛玉"}}; } class myadpter extends BaseExpandableListAdapter{ @Override public int getGroupCount() { return str.length; } @Override public int getChildrenCount(int groupPosition) { return strr[groupPosition].length; } @Override public Object getGroup(int groupPosition) { return str[groupPosition]; } @Override public Object getChild(int groupPosition, int childPosition) { return strr[groupPosition][childPosition]; } @Override public long getGroupId(int groupPosition) { return 0; } @Override public long getChildId(int groupPosition, int childPosition) { return 0; } @Override public boolean hasStableIds() { return false; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { convertView=View.inflate(MainActivity.this,R.layout.group_activity,null); TextView text= (TextView) convertView.findViewById(R.id.text_group); text.setText(str[groupPosition]); return convertView; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { convertView=View.inflate(MainActivity.this,R.layout.child_activity,null); TextView text= (TextView) convertView.findViewById(R.id.text_child); text.setText(strr[groupPosition][childPosition]); return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return false; } }