点击istview的item,控制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);
            }
        });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现Android ListView的上拉加载更多功能可以使用以下步骤: 1. 在ListView布局中添加一个FooterView,用来显示加载更多的进度条或者文字提示。 2. 监听ListView的滚动事件,当滚动到底部时,触发加载更多操作。 3. 加载更多时,显示进度条或文字提示,并请求数据。 4. 数据请求完成后,更新ListView的数据源,并隐藏进度条或文字提示。 以下是一个简单的示例代码: 1. 布局文件中添加FooterView ```xml <ListView android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent"/> <TextView android:id="@+id/footer_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone" android:gravity="center" android:text="正在加载更多..."/> ``` 2. 监听ListView滚动事件 ```java listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // do nothing } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem + visibleItemCount >= totalItemCount && !isLoadingMore) { // 滚动到底部并且没有正在加载更多时,触发加载更多操作 loadMore(); } } }); ``` 3. 加载更多操作 ```java private void loadMore() { isLoadingMore = true; footerView.setVisibility(View.VISIBLE); // 发起数据请求 requestData(new RequestCallback() { @Override public void onSuccess(List data) { // 更新ListView数据源 adapter.addData(data); isLoadingMore = false; footerView.setVisibility(View.GONE); } @Override public void onFailure() { isLoadingMore = false; footerView.setVisibility(View.GONE); } }); } ``` 4. 请求数据的示例代码 ```java private void requestData(final RequestCallback callback) { new AsyncTask<Void, Void, List>() { @Override protected List doInBackground(Void... params) { // 模拟数据请求 try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } List<String> newData = new ArrayList<>(); for (int i = 0; i < 10; i++) { newData.add("Item " + (adapter.getCount() + i)); } return newData; } @Override protected void onPostExecute(List data) { callback.onSuccess(data); } }.execute(); } private interface RequestCallback { void onSuccess(List data); void onFailure(); } ``` 以上就是一个简单的实现ListView上拉加载更多功能的示例代码,你可以根据自己的需求进行修改和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值