編輯:關於Android編程
ListView實現的列表,如果是可編輯,可刪除的,一般都要提供批量刪除功能,否則的話,一項一項的刪除體驗很不好,也給用戶帶來了很大的麻煩。
實現效果圖
具體實現代碼
select.xml<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+Ctb3sry+1s7EvP6w/Lqs0ru49kxpc3RWaWV3u7nT0NK7uPbS/rLYtcSyvL7Wo6yw/LqswcvBvbj2QnV0dG9u0ru49lRleHRWaWV3LMSsyM+yvL7Wzqpnb25lo6y1sbzgzP21vbOksLTP7NOmysK8/sqxuvLP1Mq+oaM8L3A+Cgo8aW1nIGlkPQ=="code_img_opened_cde9cf76-2928-403a-9773-41eea77ffed9" class="code_img_opened" src="https://www.android5.online/Android/UploadFiles_5356/201702/2017022316333911.gif" alt="\">
1 26 7 14 15 16 1726 37 6247 48 59 60 61
item.xml
包含一個TextView 一個CheckBox
1 26 7 19 20 27
通過自定義Adapter綁定ListView數據源,實現長按監聽,在長按監聽時候,切記將監聽事件返回ture。
1 /** 2 * @author ieasy360_1 3 * 自定義Adapter 4 */ 5 class Adapter extends BaseAdapter{ 6 private Context context; 7 private LayoutInflater inflater=null; 8 private HashMapmView ; 9 public HashMap visiblecheck ;//用來記錄是否顯示checkBox 10 public HashMap ischeck; 11 private TextView txtcount; 12 public Adapter(Context context,TextView txtcount) 13 { 14 this.context = context; 15 this.txtcount = txtcount; 16 inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 17 mView = new HashMap (); 18 visiblecheck = new HashMap (); 19 ischeck = new HashMap (); 20 if(isMulChoice){ 21 for(int i=0;i 全部實現代碼
1 package com.example.test; 2 import java.util.ArrayList; 3 import java.util.HashMap; 4 import java.util.List; 5 import android.app.Activity; 6 import android.content.Context; 7 import android.os.Bundle; 8 import android.view.ContextMenu; 9 import android.view.ContextMenu.ContextMenuInfo; 10 import android.view.LayoutInflater; 11 import android.view.View; 12 import android.view.View.OnClickListener; 13 import android.view.View.OnLongClickListener; 14 import android.view.ViewGroup; 15 import android.widget.BaseAdapter; 16 import android.widget.Button; 17 import android.widget.CheckBox; 18 import android.widget.ListView; 19 import android.widget.RelativeLayout; 20 import android.widget.TextView; 21 import android.widget.Toast; 22 23 /** 24 * @author ieasy360_1 25 * 26 */ 27 public class MulSelect extends Activity implements OnClickListener { 28 29 private ListView listview; 30 private Context context; 31 private Listarray = new ArrayList (); 32 private List selectid = new ArrayList (); 33 private boolean isMulChoice = false; //是否多選 34 private Adapter adapter; 35 private RelativeLayout layout; 36 private Button cancle,delete; 37 private TextView txtcount; 38 39 @Override 40 protected void onCreate(Bundle savedInstanceState) { 41 // TODO Auto-generated method stub 42 super.onCreate(savedInstanceState); 43 setContentView(R.layout.select); 44 context = this; 45 listview = (ListView)findViewById(R.id.list); 46 layout = (RelativeLayout)findViewById(R.id.relative); 47 txtcount = (TextView)findViewById(R.id.txtcount); 48 cancle = (Button)findViewById(R.id.cancle); 49 delete = (Button)findViewById(R.id.delete); 50 cancle.setOnClickListener(this); 51 delete.setOnClickListener(this); 52 init(); 53 adapter = new Adapter(context,txtcount); 54 listview.setAdapter(adapter); 55 56 } 57 58 void init() 59 { 60 for(int i=0;i<20;i++) 61 { 62 array.add("小明"+i); 63 } 64 } 65 66 public void onClick(View v) { 67 // TODO Auto-generated method stub 68 switch (v.getId()) { 69 case R.id.cancle: 70 isMulChoice = false; 71 selectid.clear(); 72 adapter = new Adapter(context,txtcount); 73 listview.setAdapter(adapter); 74 layout.setVisibility(View.INVISIBLE); 75 break; 76 case R.id.delete: 77 isMulChoice =false; 78 for(int i=0;i visiblecheck ;//用來記錄是否顯示checkBox 113 public HashMap ischeck; 114 private TextView txtcount; 115 public Adapter(Context context,TextView txtcount) 116 { 117 this.context = context; 118 this.txtcount = txtcount; 119 inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 120 mView = new HashMap (); 121 visiblecheck = new HashMap (); 122 ischeck = new HashMap (); 123 if(isMulChoice){ 124 for(int i=0;i
一、Socket通信簡介Android與服務器的通信方式主要有兩種,一是Http通信,一是Socket通信。兩者的最大差異在於,http連接使用的是“請求&m
很多入手了魅藍Note 3的機友們發現,在魅藍Note3上優酷居然沒有超清視頻的選項,這對於喜歡看超清視頻的機友們而言無疑是一種折磨。這種事情小編也是郁悶了
Android Fragment的回退棧點開之後按一次回退鍵只返回一次MainActivity 類public class MainActivity exte
上一篇講了VLC整個程序的模塊劃分和界面主要使用的技術,今天分析一下VLC程序初始化過程,主要是初始化界面、加載解碼庫的操作。今天主要分析一下org.videolan.v