点击istview的item,控制item的footer的展开与隐藏

本文介绍如何实现点击 ListView 的 item 来控制 footer 的显示与隐藏效果。通过自定义 Adapter 并在其中实现 changeVisable 方法来切换 footer 的可见状态,并在 getView 方法中根据当前 item 的位置设置 footer 的显示与否。
点击istview的item,控制item的footer的展开与隐藏
                
                             ​
                  效果如图所示,查看,下载更新,删除三个按钮在布局里面用footer包起来
    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="35dip"
        android:orientation="horizontal"
        android:paddingBottom="5dp"
        android:paddingTop="5dp" >
        <Button
            android:id="@+id/btn_display"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:background="@drawable/offline_button_style"
            android:focusable="false"
            android:text="查看"
            android:textColor="@color/bg_sliding_menu" />
        <Button
            android:id="@+id/btn_load"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:background="@drawable/offline_button_style"
            android:focusable="false"
            android:text="暂停"
            android:textColor="@color/bg_sliding_menu" />
        <Button
            android:id="@+id/btn_remove"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/offline_button_style"
            android:focusable="false"
            android:text="删除"
            android:textColor="@color/bg_sliding_menu" />
    </LinearLayout>

​   1.在adapter类里面写上改方法
     /**
         * 修改展开选项的位置
         * @param position
         */
        public void changeVisable(int position) {
            if (position != mLastPosition) {
                mLastPosition = position;
            } else {
                mLastPosition = -1;
            }
            notifyDataSetChanged();
        }
 2.在getview()方法里面写上
     if (position == mLastPosition) {
                itemHolder.footer.setVisibility(View.VISIBLE);
          } else {
                itemHolder.footer.setVisibility(View.GONE);
          }
 3.在listview的item点击事件里写上
         list.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
                adapter.changeVisable(position);
            }
        });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值