ExpandableListView 分类数目统计

想了几天,布局填充2个一样的分类,在 viewBinder 里把 adapter 子类填充抄过来取数字就行了。 

 ExpandableListView + SimpleCursorTreeAdapter_海天鹰的博客-CSDN博客

group_row.xml 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/group_name"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:paddingStart="?android:attr/expandableListPreferredItemPaddingLeft"
        android:text="group_name"
        android:textAppearance="?android:attr/textAppearanceListItem" />

    <TextView
        android:id="@+id/group_count"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:gravity="center"
        android:text="0" />

</LinearLayout>

DBHelper helper = new DBHelper(this);
Cursor groupCursor = helper.category();
// android.R.layout.simple_expandable_list_item_1 -> R.layout.group_row
// android.R.id.text1 ->  R.id.group_name, R.id.group_count
SimpleCursorTreeAdapter adapter = new MySimpleCursorTreeAdapter(groupCursor, this, R.layout.group_row, R.layout.favorite_row, new String[] { "category", "category" }, new int[] { R.id.group_name, R.id.group_count }, new String[] { "_id", "title", "website", "category", "website" }, new int[] { R.id.id, R.id.title, R.id.website, R.id.category, R.id.imageView_favicon });

adapter.setViewBinder(new SimpleCursorTreeAdapter.ViewBinder(){
    public boolean setViewValue(View view, Cursor cursor, int columnIndex){
        if (view.getId() == R.id.group_count) {
            TextView textView = (TextView) view;
            String s = cursor.getString(columnIndex);
            DBHelper helper = new DBHelper(FavoriteActivity1.this);
            Cursor cursor1 = helper.queryCategory(s);
            int count = cursor1.getCount();
            textView.setText("" + count);
            return true;
         }
         return false;
     }
});
expandableListView.setAdapter(adapter);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值