Hi Ted,
Maybe I have understood the theory, now, but my code still do not work.
So, my code looks like this:
//This is my list view
ListView charList = (ListView)findViewById(R.id.list);
//This is the cursor that stores all the DB rows, I tested it and it works
just fine
Cursor loadCursor = mDbHelper.fetchAllRecords();
//Setting up the from String[]
String[] from = new String[]{"name"};
//Setting up the to int[]
int[] to = new int[]{R.id.lstCharacters};
//Now, I set the SimpleCursorAdapter
SimpleCursorAdapter simplCursor = new SimpleCursorAdapter(this, R.id.list,
loadCharacterCursor, from, to);
//Setting the adapter do the list - here it crashes.
charList.setAdapter(simplCursor);
I cant see what I'm doing wrong. Can anyone shed (some) more light to the
subject?
Ricardo
On Sun, Apr 1, 2012 at 12:33 AM, Ted Scott <[email protected]> wrote:
> Hi Ricardo,
>
> First, I'm sure others will chime in if this is bad advice, but my
> understanding is that it is better to use the compatibility package and
> cursor loaders and a load manager. See http://developer.android.com/**
> reference/android/widget/**SimpleCursorAdapter.html<http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html>and
> the base CursorAdapter.
>
> That said, from is simply a list of columns in the PROJECTION exposed by
> the cursor that are of interest to the ListView ids in the to array. This
> is in order of the two arrays such that the data from from[x] is passed to
> the view with the id in to[x].
>
> Given the list view row definition:
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout
> xmlns:android="http://schemas.**android.com/apk/res/android<http://schemas.android.com/apk/res/android>
> "
> android:layout_width="fill_**parent"
> android:layout_height="34dp"
> android:gravity="bottom"
> android:orientation="**horizontal">
>
> <TextView
> xmlns:android="http://schemas.**android.com/apk/res/android<http://schemas.android.com/apk/res/android>
> "
> android:id="@+id/foo"
> android:layout_width="100dp"
> android:layout_height="30dp"
> android:textSize="16dp"
> android:gravity="center_**vertical"
> android:paddingLeft="5dip"
> android:singleLine="true"
> />
> <TextView
> xmlns:android="http://schemas.**android.com/apk/res/android<http://schemas.android.com/apk/res/android>
> "
> android:id="@+id/bar"
> android:layout_width="50dp"
> android:layout_height="30dp"
> android:textSize="20dp"
> android:gravity="right|center_**vertical"
> android:paddingLeft="5dip"
> android:singleLine="true"
> />
> </LinearLayout>
>
> And assuming that you have column1 and column2 in your cursor's
> projection, and want to map the contents of column1 to the textview foo and
> column2 to textview bar, from and to would be defined something like:
>
> String[] from = new String[] { "column1" , "coulmn2"};
> int[] to = new int[] { R.id.foo , R.id.bar };
>
> Clear as mud?
>
> -Ted
>
>
> On 3/31/2012 9:36 PM, Ricardo Santos wrote:
>
>> Hello everyone!
>>
>> I have in my application, I hace a list view that needs to be populated
>> with data from a database, I have tested my database and my app is handling
>> the data correctly, but I cant populate the list view, I have read about
>> the SimpleCursorAdapter but I cant understand how to use the class,
>> specially the from and to fields, does anyone know how to use it?
>>
>> My class is not extending ListActivity, my list view is inside a dialog.
>>
>> Ricardo
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@**
>> googlegroups.com <[email protected]>
>> To unsubscribe from this group, send email to
>> android-developers+**[email protected]<android-developers%[email protected]>
>> For more options, visit this group at
>> http://groups.google.com/**group/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en>
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to
> android-developers@**googlegroups.com<[email protected]>
> To unsubscribe from this group, send email to
> android-developers+**[email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/**group/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en