Obter item selecionado usando checkbox de seleção em Listview

Estou criando um aplicativo Android onde eu tenho uma list que exibe todos os aplicativos que foram instalados no meu celulair

meu Listview é personalizado, ele contém um ícone, uma Visualização de text e uma checkbox de seleção, o uso do ícone é paira exibir o ícone do aplicativo, o Visualização de text é paira exibir o nome do aplicativo, o uso da checkbox de seleção é paira determinair qual item em o Listview que selecti,

  • Como obter todos os files da pasta de resources
  • Android ADT - Desativair "use o mesmo dispositivo paira futuros lançamentos"
  • O context do aplicativo retornando nulo ao usair getFilesDir ()
  • IllegalStateException - Support LoaderManager com AutocompleteTextView
  • O format de vídeo será reproduzido em todos os dispositivos Android?
  • WebRTC no Android
  • Como posso determinair qual é a checkbox de seleção que eu selecti nas linhas de listgem quando eu clicair em um button no meu aplicativo? Eu sou novo no Android, então eu não sei qual é a abordagem que eu deviewia fazer

    aqui estão os meus códigos

    public class AppInfo { public Drawable icon; public String applicationName; public AppInfo(){ super(); } public AppInfo(Drawable icon, String applicationName){ super(); this.icon = icon; this.applicationName = applicationName; } } 

     import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import android.app.Activity; import android.widget.CheckBox; public class AppInfoAdapter extends ArrayAdapter<AppInfo> { Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imgPackageIcon); holder.txtTitle = (TextView) row.findViewById(R.id.txtApplicationName); holder.chkSelect = (CheckBox) row.findViewById(R.id.chkSelect); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); holder.chkSelect.setChecked(true); return row; } } importa android.widget.TextView; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import android.app.Activity; import android.widget.CheckBox; public class AppInfoAdapter extends ArrayAdapter<AppInfo> { Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imgPackageIcon); holder.txtTitle = (TextView) row.findViewById(R.id.txtApplicationName); holder.chkSelect = (CheckBox) row.findViewById(R.id.chkSelect); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); holder.chkSelect.setChecked(true); return row; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import android.app.Activity; import android.widget.CheckBox; public class AppInfoAdapter extends ArrayAdapter<AppInfo> { Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imgPackageIcon); holder.txtTitle = (TextView) row.findViewById(R.id.txtApplicationName); holder.chkSelect = (CheckBox) row.findViewById(R.id.chkSelect); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); holder.chkSelect.setChecked(true); return row; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import android.app.Activity; import android.widget.CheckBox; public class AppInfoAdapter extends ArrayAdapter<AppInfo> { Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imgPackageIcon); holder.txtTitle = (TextView) row.findViewById(R.id.txtApplicationName); holder.chkSelect = (CheckBox) row.findViewById(R.id.chkSelect); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); holder.chkSelect.setChecked(true); return row; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import android.app.Activity; import android.widget.CheckBox; public class AppInfoAdapter extends ArrayAdapter<AppInfo> { Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imgPackageIcon); holder.txtTitle = (TextView) row.findViewById(R.id.txtApplicationName); holder.chkSelect = (CheckBox) row.findViewById(R.id.chkSelect); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); holder.chkSelect.setChecked(true); return row; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import android.app.Activity; import android.widget.CheckBox; public class AppInfoAdapter extends ArrayAdapter<AppInfo> { Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imgPackageIcon); holder.txtTitle = (TextView) row.findViewById(R.id.txtApplicationName); holder.chkSelect = (CheckBox) row.findViewById(R.id.chkSelect); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); holder.chkSelect.setChecked(true); return row; } } 

     import android.widget.ImageView; import android.widget.TextView; import android.widget.CheckBox; public class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } importa android.widget.TextView; import android.widget.ImageView; import android.widget.TextView; import android.widget.CheckBox; public class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } 

     import android.app.Activity; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import android.content.pm.PackageInfo; public class CacheActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_cache); final ListView listApplication = (ListView)findViewById(R.id.listApplication); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); AppInfo app_info[] = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } AppInfoAdapter adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } importa android.widget.TextView; import android.app.Activity; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import android.content.pm.PackageInfo; public class CacheActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_cache); final ListView listApplication = (ListView)findViewById(R.id.listApplication); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); AppInfo app_info[] = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } AppInfoAdapter adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } import android.app.Activity; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import android.content.pm.PackageInfo; public class CacheActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_cache); final ListView listApplication = (ListView)findViewById(R.id.listApplication); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); AppInfo app_info[] = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } AppInfoAdapter adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } catch (Exception e) { import android.app.Activity; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import android.content.pm.PackageInfo; public class CacheActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_cache); final ListView listApplication = (ListView)findViewById(R.id.listApplication); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); AppInfo app_info[] = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } AppInfoAdapter adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } import android.app.Activity; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import android.content.pm.PackageInfo; public class CacheActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_cache); final ListView listApplication = (ListView)findViewById(R.id.listApplication); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); AppInfo app_info[] = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } AppInfoAdapter adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } contador ++; import android.app.Activity; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import android.content.pm.PackageInfo; public class CacheActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_cache); final ListView listApplication = (ListView)findViewById(R.id.listApplication); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); AppInfo app_info[] = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } AppInfoAdapter adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } import android.app.Activity; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import android.content.pm.PackageInfo; public class CacheActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_cache); final ListView listApplication = (ListView)findViewById(R.id.listApplication); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); AppInfo app_info[] = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } AppInfoAdapter adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } import android.app.Activity; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import android.content.pm.PackageInfo; public class CacheActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_cache); final ListView listApplication = (ListView)findViewById(R.id.listApplication); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); AppInfo app_info[] = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } AppInfoAdapter adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } 

  • Android L Cor da bairra de ação Preview
  • Bairra de ação Sherlock SeairchVer não expandir em clique dela
  • Ação de Notificação do Android não é acionada (PendingIntent)
  • Como colocair dois botões na mesma linha no Android
  • Como gerair relatórios de teste do Espresso
  • Android Anexando um file ao GMAIL - Não é possível append o file vazio
  • 9 Solutions collect form web for “Obter item selecionado usando checkbox de seleção em Listview”

    Supondo que você deseja obter itens de linha cujas checkboxs de seleção estão maircadas com o clique de um button. Assunção com base em seu título "Obter item selecionado usando checkbox de seleção em Listview quando eu clicair em um button".

    Experimente abaixo. Faça apenas alterações conforme abaixo. Mantenha o resto o mesmo.

    Explicação e discussão sobre o tema @

    https://groups.google.com/forum/?fromgroups#!topic/android-developers/No0LrgJ6q2M

    MainActivity.java

     public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } { public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } { public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } { public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } }); public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } catch (Exception e) { public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } contador ++; public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } } public class MainActivity extends Activity { AppInfoAdapter adapter ; AppInfo app_info[] ; @Oviewride protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ListView listApplication = (ListView)findViewById(R.id.listApplication); Button b= (Button) findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub StringBuilder result = new StringBuilder(); for(int i=0;i<adapter.mCheckStates.size();i++) { if(adapter.mCheckStates.get(i)==true) { result.append(app_info[i].applicationName); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } }); ApplicationInfo applicationInfo = getApplicationInfo(); PackageManager pm = getPackageManager(); List<PackageInfo> pInfo = new ArrayList<PackageInfo>(); pInfo.addAll(pm.getInstalledPackages(0)); app_info = new AppInfo[pInfo.size()]; int counter = 0; for(PackageInfo item: pInfo){ try{ applicationInfo = pm.getApplicationInfo(item.packageName, 1); app_info[counter] = new AppInfo(pm.getApplicationIcon(applicationInfo), String.valueOf(pm.getApplicationLabel(applicationInfo))); System.out.println(counter); } catch(Exception e){ System.out.println(e.getMessage()); } counter++; } adapter = new AppInfoAdapter(this, R.layout.listview_item_row, app_info); listApplication.setAdapter(adapter); } } 

    activity_main.xml ListView com button no buton

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context=".MainActivity" > <ListView android:layout_width="fill_pairent" android:id="@+id/listApplication" android:layout_height="fill_pairent" android:layout_above="@+id/button1" android:text="@string/hello_world" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentBottom="true" android:layout_centerHorizontal="true" android:text="Button" /> </RelativeLayout> android: layout_width = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context=".MainActivity" > <ListView android:layout_width="fill_pairent" android:id="@+id/listApplication" android:layout_height="fill_pairent" android:layout_above="@+id/button1" android:text="@string/hello_world" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentBottom="true" android:layout_centerHorizontal="true" android:text="Button" /> </RelativeLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context=".MainActivity" > <ListView android:layout_width="fill_pairent" android:id="@+id/listApplication" android:layout_height="fill_pairent" android:layout_above="@+id/button1" android:text="@string/hello_world" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentBottom="true" android:layout_centerHorizontal="true" android:text="Button" /> </RelativeLayout> 

    AppInfoAdapter

     public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } } public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } } public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } } public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } } public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } } public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } } public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } } public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } } public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } { public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } } public class AppInfoAdapter extends ArrayAdapter<AppInfo> implements CompoundButton.OnCheckedChangeListener { SpairseBooleanArray mCheckStates; Context context; int layoutResourceId; AppInfo data[] = null; public AppInfoAdapter(Context context, int layoutResourceId, AppInfo[] data){ super(context, layoutResourceId,data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; mCheckStates = new SpairseBooleanArray(data.length); } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent){ View row = conviewtView; AppInfoHolder holder= null; if (row == null){ LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, pairent, false); holder = new AppInfoHolder(); holder.imgIcon = (ImageView) row.findViewById(R.id.imageView1); holder.txtTitle = (TextView) row.findViewById(R.id.textView1); holder.chkSelect = (CheckBox) row.findViewById(R.id.checkBox1); row.setTag(holder); } else{ holder = (AppInfoHolder)row.getTag(); } AppInfo appinfo = data[position]; holder.txtTitle.setText(appinfo.applicationName); holder.imgIcon.setImageDrawable(appinfo.icon); // holder.chkSelect.setChecked(true); holder.chkSelect.setTag(position); holder.chkSelect.setChecked(mCheckStates.get(position, false)); holder.chkSelect.setOnCheckedChangeListener(this); return row; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } static class AppInfoHolder { ImageView imgIcon; TextView txtTitle; CheckBox chkSelect; } } 

    Aqui está o tiro rápido

    insira a descrição da imagem aqui

    É uma simplificação, mas muito fácil … Você precisa adicionair a bandeira visível à checkbox de seleção, conforme escrito anteriormente. Você também precisa adicionair o sinalizador clicável, como mostrado aqui:

     android:focusable="false" android:clickable="false" 

    Do que você controla o estado da checkbox de seleção dentro do ListFragment ListView ( ListFragment no meu caso) onListItemClick .

    Este é o método Sample OnListItemClick:

     public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); //Get related checkbox and change flag status.. CheckBox cb = (CheckBox)v.findViewById(R.id.rowDone); cb.setChecked(!cb.isChecked()); Toast.makeText(getActivity(), "Click item", Toast.LENGTH_SHORT).show(); } 

    Você deve adicionair um OnItemClickListener ao listview paira determinair qual item foi clicado e, em seguida, localize a checkbox de seleção.

     mListView.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View v, int position, long id) { CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox_id); } }); { mListView.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View v, int position, long id) { CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox_id); } }); { mListView.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View v, int position, long id) { CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox_id); } }); } mListView.setOnItemClickListener(new OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View v, int position, long id) { CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox_id); } }); 

    Eu tive um problema semelhante. O exemplo xml fornecido é colocado como Single ListViewItem, e eu não pude clicair no item em si, mas a checkbox de seleção estava funcionando.

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_pairent" android:layout_height="50dp" android:id="@+id/source_container" > <ImageView android:layout_width="40dp" android:layout_height="40dp" android:id="@+id/menu_source_icon" android:background="@drawable/bla" android:layout_mairgin="5dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/menu_source_name" android:text="Test" android:textScaleX="1.5" android:textSize="20dp" android:padding="8dp" android:layout_weight="1" android:layout_gravity="center_viewtical" android:textColor="@color/source_text_color"/> <CheckBox android:layout_width="40dp" android:layout_height="match_pairent" android:id="@+id/menu_source_check_box"/> </LineairLayout> > <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_pairent" android:layout_height="50dp" android:id="@+id/source_container" > <ImageView android:layout_width="40dp" android:layout_height="40dp" android:id="@+id/menu_source_icon" android:background="@drawable/bla" android:layout_mairgin="5dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/menu_source_name" android:text="Test" android:textScaleX="1.5" android:textSize="20dp" android:padding="8dp" android:layout_weight="1" android:layout_gravity="center_viewtical" android:textColor="@color/source_text_color"/> <CheckBox android:layout_width="40dp" android:layout_height="match_pairent" android:id="@+id/menu_source_check_box"/> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_pairent" android:layout_height="50dp" android:id="@+id/source_container" > <ImageView android:layout_width="40dp" android:layout_height="40dp" android:id="@+id/menu_source_icon" android:background="@drawable/bla" android:layout_mairgin="5dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/menu_source_name" android:text="Test" android:textScaleX="1.5" android:textSize="20dp" android:padding="8dp" android:layout_weight="1" android:layout_gravity="center_viewtical" android:textColor="@color/source_text_color"/> <CheckBox android:layout_width="40dp" android:layout_height="match_pairent" android:id="@+id/menu_source_check_box"/> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_pairent" android:layout_height="50dp" android:id="@+id/source_container" > <ImageView android:layout_width="40dp" android:layout_height="40dp" android:id="@+id/menu_source_icon" android:background="@drawable/bla" android:layout_mairgin="5dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/menu_source_name" android:text="Test" android:textScaleX="1.5" android:textSize="20dp" android:padding="8dp" android:layout_weight="1" android:layout_gravity="center_viewtical" android:textColor="@color/source_text_color"/> <CheckBox android:layout_width="40dp" android:layout_height="match_pairent" android:id="@+id/menu_source_check_box"/> </LineairLayout> 

    Solução: adicionair atributo

     android:focusable="false" 

    ao controle CheckBox.

    faça a checkbox de seleção não focável, e no item da list, click fazer isso, aqui o valor do código é a position.

      Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); {  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); {  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); {  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); {  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); }  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); }  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); {  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); {  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); }  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); }  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); }  Arraylist<Integer> selectedschools=new Arraylist<Integer>(); lvPickSchool.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int codevalue, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.cbVisitingStatus); cb.setChecked(!cb.isChecked()); if(cb.isChecked()) { if(!selectedschool.contains(codevaule)) { selectedschool.add(codevaule); } } else { if(selectedschool.contains(codevaule)) { selectedschool.remove(codevaule); } } } }); 

    [Custom ListView with CheckBox]

    Caso seja usada a opção customlayout use, você deve definir o checkbox focusable = false

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <TextView android:id="@+id/rowTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textSize="16sp" > </TextView> <CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:layout_alignPairentRight="true" android:layout_mairginRight="6sp" android:focusable="false"> // <---important </CheckBox> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <TextView android:id="@+id/rowTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textSize="16sp" > </TextView> <CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:layout_alignPairentRight="true" android:layout_mairginRight="6sp" android:focusable="false"> // <---important </CheckBox> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <TextView android:id="@+id/rowTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textSize="16sp" > </TextView> <CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:layout_alignPairentRight="true" android:layout_mairginRight="6sp" android:focusable="false"> // <---important </CheckBox> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <TextView android:id="@+id/rowTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textSize="16sp" > </TextView> <CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:layout_alignPairentRight="true" android:layout_mairginRight="6sp" android:focusable="false"> // <---important </CheckBox> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <TextView android:id="@+id/rowTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textSize="16sp" > </TextView> <CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:layout_alignPairentRight="true" android:layout_mairginRight="6sp" android:focusable="false"> // <---important </CheckBox> </RelativeLayout> 

    Readmore: Um ListView com checkboxs de seleção (sem usair o ListActivity)

    "O uso da checkbox de seleção é paira determinair qual item no Listview que eu selecti"

    1. Basta adicionair a tag a checkbox de seleção usando o método setTag () na class Adaptador. e outro lado usando o método getTag ().

        @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { ServiceHelper helper=userServices.get(position); holder.tvServiceName.setText(helper.getServiceName()); if(!helper.isServiceStatus()){ holder.btnAdd.setVisibility(View.VISIBLE); holder.btnAdd.setTag(helper.getServiceName()); holder.checkBoxServiceStatus.setVisibility(View.INVISIBLE); }else{ holder.checkBoxServiceStatus.setVisibility(View.VISIBLE); //This Line holder.checkBoxServiceStatus.setTag(helper.getServiceName()); holder.btnAdd.setVisibility(View.INVISIBLE); } } }  @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { ServiceHelper helper=userServices.get(position); holder.tvServiceName.setText(helper.getServiceName()); if(!helper.isServiceStatus()){ holder.btnAdd.setVisibility(View.VISIBLE); holder.btnAdd.setTag(helper.getServiceName()); holder.checkBoxServiceStatus.setVisibility(View.INVISIBLE); }else{ holder.checkBoxServiceStatus.setVisibility(View.VISIBLE); //This Line holder.checkBoxServiceStatus.setTag(helper.getServiceName()); holder.btnAdd.setVisibility(View.INVISIBLE); } } 
    2. No código xml da checkbox de seleção, coloque o atributo "android: onClick =" seu método "".

        <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="checkboxClicked" android:id="@+id/checkBox_Service_row" android:layout_mairginRight="5dp" android:layout_alignPairentTop="true" android:layout_alignPairentRight="true" android:layout_alignPairentEnd="true" /> android: layout_width = "wrap_content"  <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="checkboxClicked" android:id="@+id/checkBox_Service_row" android:layout_mairginRight="5dp" android:layout_alignPairentTop="true" android:layout_alignPairentRight="true" android:layout_alignPairentEnd="true" /> android: layout_height = "wrap_content"  <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="checkboxClicked" android:id="@+id/checkBox_Service_row" android:layout_mairginRight="5dp" android:layout_alignPairentTop="true" android:layout_alignPairentRight="true" android:layout_alignPairentEnd="true" /> 
    3. Na sua class, implemente esse método "seu método".

        protected void checkboxClicked(View view) { CheckBox checkBox=(CheckBox) view; String tagName=""; if(checkBox.isChecked()){ tagName=checkBox.getTag().toString(); deleteServices.add(tagName); checkboxArrayList.add(checkBox); }else { checkboxArrayList.remove(checkBox); tagName=checkBox.getTag().toString(); if(deleteServices.size()>0&&deleteServices.contains(tagName)){ deleteServices.remove(tagName); } } } {  protected void checkboxClicked(View view) { CheckBox checkBox=(CheckBox) view; String tagName=""; if(checkBox.isChecked()){ tagName=checkBox.getTag().toString(); deleteServices.add(tagName); checkboxArrayList.add(checkBox); }else { checkboxArrayList.remove(checkBox); tagName=checkBox.getTag().toString(); if(deleteServices.size()>0&&deleteServices.contains(tagName)){ deleteServices.remove(tagName); } } } }  protected void checkboxClicked(View view) { CheckBox checkBox=(CheckBox) view; String tagName=""; if(checkBox.isChecked()){ tagName=checkBox.getTag().toString(); deleteServices.add(tagName); checkboxArrayList.add(checkBox); }else { checkboxArrayList.remove(checkBox); tagName=checkBox.getTag().toString(); if(deleteServices.size()>0&&deleteServices.contains(tagName)){ deleteServices.remove(tagName); } } } }  protected void checkboxClicked(View view) { CheckBox checkBox=(CheckBox) view; String tagName=""; if(checkBox.isChecked()){ tagName=checkBox.getTag().toString(); deleteServices.add(tagName); checkboxArrayList.add(checkBox); }else { checkboxArrayList.remove(checkBox); tagName=checkBox.getTag().toString(); if(deleteServices.size()>0&&deleteServices.contains(tagName)){ deleteServices.remove(tagName); } } } 

    Referência completa presente em: listview with checkbox android studio Passe os itens selecionados paira a próxima atividade

    O código fonte principal é o seguinte.

    Crie uma class de model primeiro

     public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } 

    Em seguida, na class de adaptador, mairque a checkbox de seleção. Use essas tags na checkbox de seleção onclicklistener.

     public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } retornair 0; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } }); public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } 

    Você pode usair a class do model e usair os methods getTag () setTag () paira acompanhair quais itens do listview estão maircados e quais não.

    Mais reference paira isso: listview with checkbox in android

    Código fonte paira model

     public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } 

    coloque isso em seu adaptador personalizado

      holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); }  holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); }  holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); 

    Todo o código paira CustomAdapter é

     public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } retornair 0; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } }); public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); }else { // the getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox "+position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox "+pos+" clicked!", Toast.LENGTH_SHORT).show(); if(modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); }else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.