ListView Beginner Problem

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

ListView Beginner Problem

Postby loadbrain » Thu Jul 30, 2009 8:16 am

Hello,
I am trying to show a simple ListView with a result of a query to SQLite.

I have following code:
Code: Select all
      Cursor c = db.getDbEntries();
        startManagingCursor(c);

        String[] from = new String[] { NumberPlatesDatabase.KEY_TITLE, NumberPlatesDatabase.KEY_TOWN, NumberPlatesDatabase.KEY_ABBR };
        int[] to = new int[] { R.id.text1 };
        Log.i("String Array", c.getString(5));
       
        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, R.layout.number_plates_row, c, from, to);
        setListAdapter(notes);


And following xml:
main.xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:layout_width="fill_parent"
  6.  
  7.    android:layout_height="fill_parent">
  8.  
  9.  
  10.  
  11.   <ListView android:id="@android:id/list"
  12.  
  13.        android:layout_width="wrap_content"
  14.  
  15.        android:layout_height="wrap_content"/>
  16.  
  17.   <TextView android:id="@android:id/empty"
  18.  
  19.        android:layout_width="wrap_content"
  20.  
  21.        android:layout_height="wrap_content"
  22.  
  23.        android:text="@string/no_number_plates"/>          
  24.  
  25. </LinearLayout>
  26.  
  27.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

and rows.xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <TextView android:id="@+id/text1"
  4.  
  5.    xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="fill_parent"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


All I want is a simple List showing all entries (about 117) but I always only get the first.

Somehow I do not understand the use of ListView with xml, can anybody help me???
loadbrain
Freshman
Freshman
 
Posts: 3
Joined: Thu Jul 30, 2009 8:10 am

Top

Postby arams » Thu Jul 30, 2009 1:10 pm

i think u add the string into the textview.

refer this:
http://developer.android.com/guide/tuto ... tview.html
arams
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Fri May 08, 2009 7:45 am

Postby loadbrain » Thu Jul 30, 2009 2:09 pm

Thanks, but in the example is a static array, how to do this with the managedCursor?
loadbrain
Freshman
Freshman
 
Posts: 3
Joined: Thu Jul 30, 2009 8:10 am

Postby TheChosen » Fri Jul 31, 2009 2:07 pm

Look at the NotePad example. Especially at step 12: NotePad example.
TheChosen
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 06, 2009 7:18 pm
Location: Germany

Postby loadbrain » Thu Aug 06, 2009 9:43 am

Finally I got it...
What I forgot and what did not make it was the column _id in my query...
I thought it is enough to have this column but not that I must include it in the query so now everything is working fine...
loadbrain
Freshman
Freshman
 
Posts: 3
Joined: Thu Jul 30, 2009 8:10 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests