K
K
kirchevsky2012-06-21 21:11:33
Android
kirchevsky, 2012-06-21 21:11:33

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:

  1. <TextView android:text="@+id/TextView01" 
  2.           android:layout_height="wrap_content" 
  3.           android:id="@+id/label"
  4.       android:textSize="30dp" 
  5.       android:layout_marginTop="6dp" 
  6.       android:layout_width="fill_parent" 
  7.       android:textColor="#000000">
  8. </TextView>
  9. <TextView android:text="@+id/TextView02" 
  10.           android:layout_height="wrap_content" 
  11.           android:id="@+id/label_desc"
  12.       android:textSize="10dp" 
  13.       android:layout_marginTop="6dp" 
  14.       android:layout_width="fill_parent"
  15.       android:layout_below=" id /TextView01"
  16.       android:textColor="#cccccc">

And there is actually a piece where, in which we fill the ListView, and I also understand that I am writing some kind of nonsense in this piece and still I dare to get advice and maybe a couple of slaps in the face ...
  1.  cursor = dbHelper.fetchAll();<br>
  2. startManagingCursor(cursor);
  3.  
  4. String[] from = new String[] { OurAppDbAdapter.KEY_TTNNUM };
  5. String[] from2 = new String[] { OurAppDbAdapter.KEY_SUM };
  6. int[] to = new int[] { R.id.label };
  7. int[] to2 = new int[] {R.id.label_desc};
  8. @SuppressWarnings("deprecation")
  9. SimpleCursorAdapter notes = new SimpleCursorAdapter(this,R.layout.ttn_row, cursor, from, to);
  10. SimpleCursorAdapter notesdesc = new SimpleCursorAdapter(this,R.layout.ttn_row, cursor, from2, to2);
  11. setListAdapter(notes);
  12. setListAdapter(notesdesc);

Of course, this does not work, so tell me how to do it in order to throw two different data sets - one into one TextView, and the second into the second ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MetAmfetamine, 2012-06-21
@MetAmfetamine

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 question

Ask a Question

731 491 924 answers to any question