Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I use different views for children in a ExpandableListView using a SimpleCursorTreeAdapter?
    primarykey
    data
    text
    <p>I would like to use a database-backed ExpandableListView where the child items should be shown in one of two different views depending on a database field.</p> <p>(if an item has the flag "done" set in the database, it should be displayed in gray, else it should be displayed in white.)</p> <p>This is how I bind the ExpandableListView to the database:</p> <pre><code>dbAdapter = new TasksDbAdapter(this); dbAdapter.open(); c = dbAdapter.getTaskGroupsInList(listId); startManagingCursor(c); dbTreeAdapter = new TaskListTreeAdapter( getApplicationContext(), c, listId, R.layout.listgroupitem, R.layout.listitem, new String[] { TaskDbAdapter.KEY_TASKTYPE_NAME }, new int[] { R.id.groupName }, new String[] { TaskDbAdapter.KEY_LISTITEMS_AMOUNT, TaskDbAdapter.KEY_UNITS_NAME, TaskDbAdapter.KEY_TASK_NAME }, new int[] { R.id.tvItemAmount, R.id.tvItemUnit, R.id.tvItemName }); </code></pre> <p>This is the getChildView method of the Adapter:</p> <pre><code> public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { View vReturnView = null; Cursor cGroupsTemp = dbAdapter.getGroups(listId); if (cGroupsTemp.moveToPosition(groupPosition)) { long groupId = cGroupsTemp.getLong(cGroupsTemp.getColumnIndex(KEY_PRODTYPE_ID)); Cursor cChildsTemp = dbAdapter.getChildren(listId, groupId); if (cChildsTemp.moveToPosition(childPosition)) { long childId = cChildsTemp.getLong(cChildsTemp.getColumnIndex(KEY_LISTITEMS_ID)); boolean bought = cChildsTemp.getInt(cChildsTemp.getColumnIndex(KEY_DONE)) &gt; 0; LayoutInflater inflater = getLayoutInflater(); if (bought) { vReturnView = inflater.inflate(R.layout.listenlistitemdone, null); } else { vReturnView = inflater.inflate(R.layout.listenlistitem, null); } } } return vReturnView; } </code></pre> <p>Unfortunately, the two different views are not shown correctly. Does anyone know why? Do the two views have to belong to a common ViewGroup? I did not find any methods like getViewTypeCount() or getItemViewType() in the Adapter. Are they not needed for this Adapter? Do the elements in the two Views have to have the same IDs (as the adapter only binds one single ID to a database column)?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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