当前位置:  首页  >  PHP资讯  >  业界资讯

Android中CheckBox多项选择当前的position信息提交的示例代码

这篇文章主要介绍了Android中CheckBox多项选择当前的position信息提交的示例代码,非常不错,具有参考借鉴价值,需要的朋友可以参考下

先给大家展示下效果图:

废话不多说了,下面通过示例代码给大家介绍checkbox 多项选择当前的position信息提交,具体代码如下所示:

 package com.dplustours.b2c.View.activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.Toast; import com.dplustours.b2c.R; import com.dplustours.b2c.View.application.MyApplication; import com.dplustours.b2c.View.application.UIHelper; import java.util.ArrayList; import java.util.HashMap; /** * Created by zhq_zhao on 2017/7/7. */ public class ElseSelectCarinfosActivity extends BaseActivity implements View.OnClickListener { private com.dplustours.b2c.View.view.MyListView else_listview; private Button next_step; private static CheckBox iv_select; private ArrayList elsetcarDetails; @Override protected String setHeadStyleTitle() { return "其他选择"; } @Override protected void requestData() { //租车信息列表 elsetcarDetails = new ArrayList(); MulAdapter mRentcarDetailsAdapter = new MulAdapter(this, elsetcarDetails); else_listview.setAdapter(mRentcarDetailsAdapter); elsetcarDetails.add(1); elsetcarDetails.add(1); elsetcarDetails.add(1); mRentcarDetailsAdapter.notifyDataSetChanged(); else_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<&#63;> parent, View view, int position, long id) { // 取得ViewHolder对象,这样就省去了通过层层的findViewById去实例化我们需要的cb实例的步骤 MulAdapter.ViewHolder viewHolder = (MulAdapter.ViewHolder) view.getTag(); viewHolder.iv_select.toggle();// 把CheckBox的选中状态改为当前状态的反,gridview确保是单一选中 MulAdapter.getIsSelected().put(position, viewHolder.iv_select.isChecked());////将CheckBox的选中状况记录下来 if (viewHolder.iv_select.isChecked() == true) { Toast.makeText(ElseSelectCarinfosActivity.this,"对勾"+position,Toast.LENGTH_LONG).show(); } else { Toast.makeText(ElseSelectCarinfosActivity.this,"取消"+position,Toast.LENGTH_LONG).show(); } Toast.makeText(ElseSelectCarinfosActivity.this,"当前"+position,Toast.LENGTH_LONG).show(); } }); } @Override protected View getSuccessView() { View view = View.inflate(MyApplication.context, R.layout.activity_else_car, null); else_listview = (com.dplustours.b2c.View.view.MyListView) view.findViewById(R.id.else_listview); next_step = (Button) view.findViewById(R.id.next_step); next_step.setOnClickListener(this); return view; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.next_step: UIHelper.Go(ElseSelectCarinfosActivity.this, CarInfosOkActivity.class); break; default: break; } } public static class MulAdapter extends BaseAdapter { private LayoutInflater inflater = null;//导入布局 private Context context; //上下文 private ArrayList list; // 控制CheckBox选中情况 private static HashMap isSelected; //导入布局 public MulAdapter(Context context, ArrayList list) { this.cOntext= context; this.list = list; inflater = LayoutInflater.from(context); isSelected = new HashMap(); initData(); } private void initData() { //初始化isSelected的数据 for (int i = 0; i  getIsSelected() { return isSelected; } public void setIsSelected(HashMap isSelected) { MulAdapter.isSelected = isSelected; } } } <&#63;xml version="1.0" encoding="utf-8"&#63;>                  

以上所述是小编给大家介绍的Android 中CheckBox多项选择当前的position信息提交的示例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

内容推荐:免费高清PNG素材下载
吐了个 "CAO" !
扫码关注 PHP1 官方微信号
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved PHP1.CN 第一PHP社区 版权所有 京ICP备19059560号-4