Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Displaying Cursor Results from DB in ListView
    primarykey
    data
    text
    <p>I have been trying to get my Cursor to display correctly in listview. it displays correctly when using a toast so the cursor is retrieving the data correctly but i'm having trouble making it display in list format. </p> <p>Should be 6 columns in each row.</p> <p>It only displays one row with no data. I'm sure it is a very basic problem. Maybe somebody could tell me where I'm going wrong, I would be grateful.</p> <p>DisplayCursor.Java</p> <pre><code>public class DisplayCursor extends ListActivity { MyDBManager db = new MyDBManager(this); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_cursor); db.open(); Cursor cursor = db.getAllRows(); startManagingCursor(cursor); String[] columns = new String[] { MyDBManager.KEY_DESCRIPTION, MyDBManager.KEY_PERCENTAGE, MyDBManager.KEY_PRICE, MyDBManager.KEY_VOLUME, MyDBManager.KEY_VFM, MyDBManager.KEY_QUANTITY }; int[] to = new int[] { R.id.description,R.id.perc,R.id.price,R.id.units,R.id.vol, R.id.vfm }; SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor, columns, to); this.setListAdapter(mAdapter); db.close(); } } </code></pre> <p>row.xml</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:id="@+id/description" android:layout_width="140dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="27dp" /&gt; &lt;TextView android:id="@+id/vol" android:layout_width="30dp" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/description" android:layout_alignBottom="@+id/description" android:layout_toRightOf="@+id/description" /&gt; &lt;TextView android:id="@+id/perc" android:layout_width="30dp" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/vol" android:layout_alignBottom="@+id/vol" android:layout_toRightOf="@+id/vol" /&gt; &lt;TextView android:id="@+id/price" android:layout_width="30dp" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/perc" android:layout_alignBottom="@+id/perc" android:layout_toRightOf="@+id/perc" /&gt; &lt;TextView android:id="@+id/units" android:layout_width="30dp" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/price" android:layout_alignBottom="@+id/price" android:layout_toRightOf="@+id/price" /&gt; &lt;TextView android:id="@+id/vfm" android:layout_width="80dp" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/units" android:layout_alignBottom="@+id/units" android:layout_toRightOf="@+id/units" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>activity_display_cursor.xml</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="wrap_content" android:layout_height="wrap_content"&gt; &lt;ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; &lt;TextView android:id="@android:id/empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/nodata"/&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    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.
 

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