二级列表的使用,上拉刷新,下拉加载

首先要先导一个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;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值