Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not 100% sure what you are trying to do, but part of your problem might be related to the condition in your <code>onClick</code> method:</p> <pre><code>if(v.isSelected()) </code></pre> <p>I think you want that to read</p> <pre><code>if(v.isChecked()) </code></pre> <p><code>isSelected</code> is inherited from View, and it means something different from <code>isChecked</code></p> <p>Also, the whether the CheckBox is checked or not is independent from your data model since it is a recycled view. Your CheckBox should be checked based on <code>entry</code> (I'm assuming your <code>TextInfo</code> class has an <code>isChecked()</code> method that returns a boolean:</p> <pre><code>@Override public View getView(final int position, View convertView, ViewGroup parent) { TaskInfo entry = mListAppInfo.get(position); if (convertView == null) { LayoutInflater inflater = LayoutInflater.from(mContext); //System.out.println("Setting LayoutInflater in TaskAdapter " +mContext +" " +R.layout.taskinfo +" " +R.id.tmbox); convertView = inflater.inflate(R.layout.taskinfo,null); } ImageView ivIcon = (ImageView)convertView.findViewById(R.id.tmImage); ivIcon.setImageDrawable(entry.getIcon()); TextView tvName = (TextView)convertView.findViewById(R.id.tmbox); tvName.setText(entry.getName()); CheckBox checkBox = (CheckBox)v.findViewById(R.id.tmbox); checkBox.setChecked(entry.isChecked()); } </code></pre> <p>I don't think you need the <code>View.OnClickListener</code> you are attaching to <code>convertView</code>. You should handle that in the <code>OnItemClickListener</code> attached to the <code>ListView</code>. Assuming your <code>ListView</code> is called <code>listView</code> and <code>TaskInfo</code> instances have <code>setChecked</code> and <code>isChecked</code> methods:</p> <pre><code>listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { entry = mListAppInfo.get(position); entry.setChecked(!entry.isChecked()); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload