Answer the question
In order to leave comments, you need to log in
How to add data to ListView using SimpleCursorAdapter?
Good day, I'm afraid to be stupid, but it's better to ask than not to ask, and therefore the following question arose - how to add two data sets to the ListView?
There is a line template:
- <TextView android:text="@+id/TextView01"
- android:layout_height="wrap_content"
- android:id="@+id/label"
- android:textSize="30dp"
- android:layout_marginTop="6dp"
- android:layout_width="fill_parent"
- android:textColor="#000000">
- </TextView>
- <TextView android:text="@+id/TextView02"
- android:layout_height="wrap_content"
- android:id="@+id/label_desc"
- android:textSize="10dp"
- android:layout_marginTop="6dp"
- android:layout_width="fill_parent"
- android:layout_below=" id /TextView01"
- android:textColor="#cccccc">
- cursor = dbHelper.fetchAll();<br>
- startManagingCursor(cursor);
- String[] from = new String[] { OurAppDbAdapter.KEY_TTNNUM };
- String[] from2 = new String[] { OurAppDbAdapter.KEY_SUM };
- int[] to = new int[] { R.id.label };
- int[] to2 = new int[] {R.id.label_desc};
- @SuppressWarnings("deprecation")
- SimpleCursorAdapter notes = new SimpleCursorAdapter(this,R.layout.ttn_row, cursor, from, to);
- SimpleCursorAdapter notesdesc = new SimpleCursorAdapter(this,R.layout.ttn_row, cursor, from2, to2);
- setListAdapter(notes);
- setListAdapter(notesdesc);
Answer the question
In order to leave comments, you need to log in
A ListView can only have one Adapter.
The working code will look something like this:
cursor = dbHelper.fetchAll();
startManagingCursor(cursor);
String[] from = new String[] { OurAppDbAdapter.KEY_TTNNUM, OurAppDbAdapter.KEY_SUM };
int[] to = new int[] { R.id.TextView01, R.id.TextView02 }; // id TextView в R.layout.ttn_row
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,R.layout.ttn_row, cursor, from, to);
setListAdapter(notes);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question