Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One of the recommended ways to improve the performance of a listView is using a <a href="http://developer.android.com/training/improving-layouts/smooth-scrolling.html#ViewHolder" rel="nofollow">ViewHolder</a> in the <a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html#getView%28int,%20android.view.View,%20android.view.ViewGroup%29" rel="nofollow">getView()</a> method. This ViewHolder object is usually attached to the view using the <a href="http://developer.android.com/reference/android/view/View.html#setTag%28int,%20java.lang.Object%29" rel="nofollow">setTag()</a> method to be able to retrieve all the views in the row in, for instance, an onClick(View) listener method. </p> <p>In your case, you could use the same method, but in the ToggleButton, to attach to it an object with the important information of the row. Then, in the <a href="http://developer.android.com/reference/android/widget/CompoundButton.OnCheckedChangeListener.html" rel="nofollow">onCheckedChangedListener</a>, you will receive the ToggleButton that has been pressed, and using the getTag() method you could obtain the previously stored object, with all the information you need to update your database. Something like this:</p> <pre><code> public View getView(int position, View convertView, ViewGroup parent) { //Other stuff here ToggleButton tb = (ToggleButton)row.findViewById(R.id.toggle_button); //Attach to the toggle button whatever object you need tb.setTag("Put an object here"); tb.setOnCheckedChangedListener(new OnCheckedChangedListener(){ @Override public void onCheckedChanged(CompoundButton button, boolean isChecked){ Object relatedData = button.getTag(); //Update the database with the relatedData } }); //Other stuff return row; } </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