Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try like this </p> <pre><code> @Override public View getView(int position, View convertView, ViewGroup parent) { // Planet to display Planet planet = (Planet) this.getItem(position); // The child views in each row. CheckBox checkBox; TextView textView; // Create a new row view if (convertView == null) { convertView = inflater.inflate(R.layout.simplerow, null); // Find the child views. textView = (TextView) convertView.findViewById(R.id.rowTextView); checkBox = (CheckBox) convertView.findViewById(R.id.CheckBox01); // Optimization: Tag the row with it's child views, so we don't // have to // call findViewById() later when we reuse the row. convertView.setTag(new PlanetViewHolder(textView, checkBox)); // If CheckBox is toggled, update the planet it is tagged with. checkBox.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; Planet planet = (Planet) cb.getTag(); planet.setChecked(cb.isChecked()); } }); } // Reuse existing row view else { // Because we use a ViewHolder, we avoid having to call // findViewById(). PlanetViewHolder viewHolder = (PlanetViewHolder) convertView .getTag(); checkBox = viewHolder.getCheckBox(); textView = viewHolder.getTextView(); } // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBox.setTag(planet); // Display planet data checkBox.setChecked(planet.isChecked()); textView.setText(planet.getName()); return convertView; } </code></pre> <p>See this example <a href="http://windrealm.org/tutorials/android/listview-with-checkboxes-without-listactivity.php" rel="nofollow">http://windrealm.org/tutorials/android/listview-with-checkboxes-without-listactivity.php</a></p>
 

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