ListView全選刪除CheckBox
adapter:
public class listAdapter_shop extends BaseAdapter {
private Context context;
private List<ShopData> list;
private onChecked checked;
public void setChecked(onChecked checked) {
this.checked = checked;
}
public listAdapter_shop(Context context, List list){
this.context = context;
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
//獲得每個item
final ShopData data_map = (ShopData) list.get(position);
ViewHolder viewHolder = null;
if (convertView == null){
//例項化物件
convertView = LayoutInflater.from(context).inflate(R.layout.shop_listview_item,null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) convertView.findViewById(R.id.shop_item_title);
viewHolder.price = (TextView) convertView.findViewById(R.id.shop_item_price);
viewHolder.classify = (TextView) convertView.findViewById(R.id.shop_item_classify);
viewHolder.amount = (TextView) convertView.findViewById(R.id.shop_item_amount);
viewHolder.checkBox = (CheckBox) convertView.findViewById(R.id.shop_item_checkbox);
viewHolder.images = (ImageView) convertView.findViewById(R.id.shop_item_img);
viewHolder.edit_btn = (Button) convertView.findViewById(R.id.shop_item_editamount);
convertView.setTag(viewHolder);
}else {
viewHolder = (ViewHolder)convertView.getTag();
}
//設定控制元件內容
viewHolder.title.setText(data_map.getmTitle());
viewHolder.price.setText("¥"+data_map.getmPrice()+"");
viewHolder.classify.setText(data_map.getmClassify());
viewHolder.amount.setText(data_map.getmAmount()+" "+"噸");
viewHolder.checkBox.setChecked(data_map.isChecke());
// viewHolder.images.setImageResource(0);
//
viewHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checked != null){
//回撥方法傳引數
data_map.setChecke(isChecked);
checked.CheckedChanged(position,isChecked);
}
}
});
viewHolder.edit_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return convertView;
}
public class ViewHolder{
TextView title;
TextView price;
TextView classify;
TextView amount;
CheckBox checkBox;
ImageView images;
Button edit_btn;
}
public static interface onChecked{
//選擇點選事件回撥
public void CheckedChanged(int position, boolean isChecked);
//修改購買數量事件回撥
public void AmountChanged();
}
private int num = 0;
private Button subtract,plus,cancel,sure;
private EditText text;
private AlertDialog.Builder builder;
private AlertDialog dialog;
}
實體類:
package com.example.cuboo.mlcircles.DataClass;
/**
* Created by cuboo on 2016/11/23.
*/
public class ShopData {
private String mTitle;
private float mPrice;
private String mClassify;
private int mAmount;
private boolean Checke;
public void setChecke(boolean checke) {
Checke = checke;
}
public boolean isChecke() {
return Checke;
}
public ShopData(String mTitle, float mPrice, String mClassify, int mAmount){
this.mTitle = mTitle;
this.mPrice = mPrice;
this.mClassify = mClassify;
this.mAmount = mAmount;
}
public String getmTitle() {
return mTitle;
}
public void setmTitle(String mTitle) {
this.mTitle = mTitle;
}
public float getmPrice() {
return mPrice;
}
public void setmPrice(float mPrice) {
this.mPrice = mPrice;
}
public String getmClassify() {
return mClassify;
}
public void setmClassify(String mClassify) {
this.mClassify = mClassify;
}
public int getmAmount() {
return mAmount;
}
public void setmAmount(int mAmount) {
this.mAmount = mAmount;
}
}
相關文章
- javascript實現 checkbox全選和批量刪除功能JavaScript
- js checkbox 全選 取消全選JS
- vue.js單選全選刪除Vue.js
- vue checkbox 實現全選,取消全選Vue
- 安卓開發:listview長按進入多選刪除操作安卓View
- Jquery實現頁面的新增、刪除、全選、取消全選、漸變色jQuery
- iOS 多選刪除(附tableViewTips及單選刪除)iOSView
- checkbox 核取方塊全選程式碼
- jQuery核取方塊checkbox的全選和反選jQuery
- 搭建直播平臺,Android ListView 長按刪除列表項AndroidView
- vue 工作專案中 實現訊息列表的 全選,反選,刪除功能Vue
- 點選刪除按鈕彈出是否刪除提示框
- 選中取消push和splice刪除
- 28-Beego優選刪除商品Go
- 原生js多選框選中排序及刪除JS排序
- jQuery點選按鈕刪除div元素jQuery
- 點選新增或者刪除表格行詳解
- dbca刪除資料庫時選項灰色資料庫
- JavaScript獲取選中checkbox valueJavaScript
- js判斷checkbox是否選中JS
- jQuery操作checkbox選擇程式碼jQuery
- checkbox及css實現點選下拉選單CSS
- win10右鍵skydrive pro選項怎麼刪除_win10右鍵選單中skydrive pro選項的刪除方法Win10
- 短視訊app開發,左滑刪除或長按彈出刪除選擇框APP
- win10 開始選單照片記錄怎麼刪除 win10刪除開始選單記錄方法Win10
- win10怎麼刪除右鍵多餘選項 win10刪除右鍵多餘選項的方法Win10
- php(js)批量刪除/單個刪除PHPJS
- 如何擴大CheckBox點選區域
- 工作293:調節刪除順序刪除
- 點選文字選中或取消選中checkbox核取方塊
- JavaScript刪除核取方塊選中的表格行JavaScript
- 刪除按鈕點選後的虛線輪廓
- 如何刪除 Mac 儲存空間的其他選項?Mac
- IDEA刪除已經廢棄不用的jdk選項IdeaJDK
- (已刪除)
- 2020-10-26 listview單選儲存View
- mysql刪除主鍵索引,刪除索引語法MySql索引
- 使用node指令碼全自動刪除豆瓣評論與帖子指令碼
- JavaScript獲取選中checkbox核取方塊的選中值JavaScript