0

I'm beeing bit confused here.

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.bugs_list_item, itemCursor, 
            new String[] {db.KEY_ROWID, db.BUGS_DATE, db.BUGS_DESCRIPTION}, 
            new int[] {R.id.bug_id, R.id.bug_date, R.id.bug_description});

This basically shows me a ListView with date and description but no id (I just get blank space in place of id). _id field is primary key, it's an integer.

See how it looks on the img

enter image description here

XML file:

<?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:stretchColumns="1" 
    >
        <TableRow 
        android:id="@+id/tableRow1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
            <TextView             
            android:id="@+id/bug_id" 
            android:layout_width="5dip" 
            android:layout_height="wrap_content"
            android:padding="3dip"                      
            >
            </TextView>
            <TextView            
            android:id="@+id/bug_date" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:padding="3dip"
            android:gravity="right"
            >
            </TextView>
            <TextView            
            android:id="@+id/bug_description" 
            android:layout_width="180dip" 
            android:layout_height="wrap_content"
            android:padding="3dip"
            android:gravity="right"
            >
            </TextView>
        </TableRow>
    </TableLayout>

create table query:

BUGS_CREATE = "CREATE TABLE bugs (_id INTEGER NOT NULL PRIMARY KEY, date DATE DEFAULT (DATETIME('NOW')) NOT NULL, description TEXT) ";
RRUZ
  • 134,889
  • 20
  • 356
  • 483
Jacek Kwiecień
  • 12,397
  • 20
  • 85
  • 157

4 Answers4

0

It's very important that your "id-field" does have the name "_id", else it might not work.

poitroae
  • 21,129
  • 10
  • 63
  • 81
0

whats the XML of your list view rows look like? have you set the ID correctly?

EDIT:
Since your XML file seems to be set up correctly, I now believe your problem is something else. It could be that the data for the bug_id field is not being stored or retrieved properly from your database.

This is from android docs:
'Be sure to include an integer column named "_id" (with the constant _ID) for the IDs of the records. You should have this field whether or not you have another field (such as a URL) that is also unique among all records. If you're using the SQLite database, the _ID field should be the following type:

INTEGER PRIMARY KEY AUTOINCREMENT'

Try to change your create table SQL to give your bug_id field an alias like this:

bug_id as _id integer primary key autoincrement,

as opposed to:

bug_id integer primary key autoincrement,
Ozzy
  • 8,244
  • 7
  • 55
  • 95
0

Simply get the ID's from this code & paste this code to your Database.java file -

String[] return_result()
{

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(tableName, new String[] { "_id", "date", "description"},null, null, null, null, null);
    String[] result = new String[cursor.getCount()];
    int i = 0;
    if(cursor.moveToFirst())
    {
        do
        {
            result[i]= cursor.getString(cursor.getColumnIndex("_id"));
            i++;
        }while(cursor.moveToNext());
    }
    if (cursor!=null && !cursor.isClosed()) 
    {
        cursor.close();
        db.close();
    }
    return result;
}

In your main java file use like this -

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.bugs_list_item, itemCursor, 
        new String[] {db.return_result(), db.BUGS_DATE, db.BUGS_DESCRIPTION}, 
        new int[] {R.id.bug_id, R.id.bug_date, R.id.bug_description});
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
0

Found the issue:

    android:layout_width="5dip"             
    android:padding="3dip" 

Layout width was only 5px, when I padded text by 3px it probably dissapeared below another layout... geez

Jacek Kwiecień
  • 12,397
  • 20
  • 85
  • 157