Note that there are some explanatory texts on larger screens.

plurals
  1. POListView with conditional formatting doesn't work properly(using a ViewBinder)
    text
    copied!<p><strong>Auxiliary Problem</strong></p> <p>Hi, could anyone please help me understand the behavior of <code>SimpleCursorAdapter.ViewBinder.setViewValue</code>?</p> <p>It seems that it is called more than once for each row in the <code>ListView</code>. Does the number of calls depend on the number of rows in the ListView? Or number of items in the cursor of <code>SimpleCursorAdapter</code>? Also, what are the significance of the parameters passed to the function?</p> <h2>Main Problem</h2> <p>I'm having this strange problem while trying to create a simple <code>ListView</code> of <code>CheckedTextViews</code>. I wanted to reduce the opacity of the rows which are checked. The code I wrote worked, except that it will always reduce the opacity of one extra row. </p> <p>Making the layout_height of the <code>ListView</code> to match_parent solved the issue for some cases. But the problem still persists when I open the keyboard for editing and the ListView somehow gets required.</p> <hr> <p>Please find the codes here </p> <p>Code to fill the items in <code>ListActivity</code>:</p> <pre><code>private void fillDataToList() { Cursor all_taskCursorCursor = mDbHelper.fetchAllTask(); startManagingCursor(all_taskCursorCursor); String[] from = new String[]{TaskDbAdapter.KEY_TITLE}; int[] to = new int[]{R.id.task_title}; SimpleCursorAdapter tasks = new SimpleCursorAdapter(this, R.layout.task_row, all_taskCursorCursor, from, to); tasks.setViewBinder(new ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if(columnIndex == 1) { CheckedTextView ctv = (CheckedTextView) view; String text = cursor.getString(cursor.getColumnIndexOrThrow(TaskDbAdapter.KEY_TITLE)); boolean checked = cursor.getInt(cursor.getColumnIndexOrThrow(TaskDbAdapter.KEY_COMPLETED)) == 1 ? true : false; ctv.setText(text); ctv.setChecked(checked); if (checked == true) { AlphaAnimation animation = new AlphaAnimation(1, 0.25f); animation.setFillAfter(true); ctv.setAnimation(animation); ctv.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG); } return true; } return false; } }); setListAdapter(tasks); } </code></pre> <p>The layout of ListView - </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;/ListView&gt; &lt;TextView android:id="@android:id/empty" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/no_task" android:padding="10dp" android:gravity="center_vertical|center_horizontal" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Layout for each row -</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;CheckedTextView android:id="@+id/task_title" android:layout_width="fill_parent" android:layout_height="50dp" android:padding="10dp" android:textAppearance="?android:attr/textAppearanceMedium" android:checkMark="?android:attr/listChoiceIndicatorMultiple" /&gt; &lt;/LinearLayout&gt; </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