Ok nevermind what I just said. I now understand what you are talking
about.
Thank you very much!!! I have been banging my head on this for several
days now and this fixes it!
For other people with this problem this is what I did:
SimpleCursorAdapter List=
new SimpleCursorAdapter(this, R.layout.check_row_cursor,
m_Cursor,
new
String[]{DBStorage.DATABASE_TITLE,
DBStorage.DATABASE_CHECKED,
DBStorage.DATABASE_STUFF},
new int[]{ R.id.IsChecked,
R.id.IsChecked,
R.id.stuff});
List.setViewBinder( new SimpleCursorAdapter.ViewBinder()
{
public boolean setViewValue(View view, Cursor cursor,
int
columnIndex)
{
int nCheckedIndex =
cursor.getColumnIndex(DBStorage.DATABASE_CHECKED);
if(columnIndex == nCheckedIndex )
{
CheckBox cb = (CheckBox) view;
boolean bChecked =
(cursor.getInt(nCheckedIndex ) != 0);
cb.setChecked(bChecked );
return true;
}
return false;
}
});
I really appreciate this!! Thanks Hielko !!!
On Apr 12, 5:29 pm, SnowDrifter <[EMAIL PROTECTED]> wrote:
> How is this done? I am not having any problems setting String and
> integer data through the SimpleCursorAdapter constructor at onCreate
> but I can't figure out how to bind the check state of the checkbox
> with this method, it always wants to bind to the text field of the
> checkbox.
>
> Here is how I am setting up my SimpleCursorAdapter:
>
> SimpleCursorAdapter tasks =
> new SimpleCursorAdapter(this, R.layout.check_row_cursor,
> m_Cursor,
> new String[]{DBStorage.DATABASE_TITLE,
> DBStorage.DATABASE_STUFF},
> new int[]{ R.id.IsChecked,
> R.id.stuff});
>
> The From[] and To[] fields are similar to a ViewBind are they not? I
> guess I don't understand how to bind to the isChecked() method of the
> CheckBox.
>
> On Apr 12, 5:13 pm, Hielko <[EMAIL PROTECTED]> wrote:
>
> > The best approach is to let your ListActivity implement the ViewBinder
> > interface, and set your checkbox in the setViewValue method.
>
> > On Apr 13, 12:52 am, SnowDrifter <[EMAIL PROTECTED]> wrote:
>
> > > I am having trouble updating the state of a Checkbox inside a
> > > SimpleCursorAdapter. I want to update the checkbox to reflect some
> > > data in my DB at the start of my ListActivity. My Layout is as
> > > follows:
>
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> > > android"
> > > android:orientation="vertical"
> > > android:layout_width="fill_parent"
> > > android:layout_height="fill_parent"
>
> > > <CheckBox android:id="@+id/IsChecked"
> > > android:layout_width="fill_parent"
> > > android:layout_height="wrap_content"
> > > android:focusable="false"
> > > android:clickable="false"/>
> > > <TextView android:id="@+id/stuff"
> > > android:layout_width="wrap_content"
> > > android:layout_height="wrap_content"
> > > android:textStyle="italic"/>
> > > </LinearLayout>
>
> > > What I am trying to do is to set the state of the checkbox at the
> > > start but it does not work. I have tried putting it in: onStart(),
> > > onPause(), onContentChanged(), onJustAboutEverything() and it does not
> > > want to update.
>
> > > Just to make sure I wasn't crazy I put it in onListItemClick() and it
> > > worked when I clicked an item (everything else would update), but this
> > > is obviously not a solution.
>
> > > As a second experiment It tried it in onOptionsItemSelected which gets
> > > called when the menu is pressed but this mysteriously did not work. I
> > > am mystified by this problem and I need to figure it!
>
> > > Any ideas where I can put the update? Just for completeness, here is
> > > my update code:
>
> > > protected void UpdateCheckboxes()
> > > {
> > > ListView tempListView = this.getListView();
> > > int nNumRows = tempListView.getCount();
> > > //setup the check boxes to reflect the data
> > > for(int idx = 0; idx < nNumRows; idx++)
> > > {
> > > CheckBox cb = (CheckBox)((LinearLayout)
> > > tempListView.getChildAt(idx)).getChildAt(0);
> > > boolean bIsChecked = m_tasks.get(idx).isChecked;
> > > cb.setChecked(bIsChecked );
> > > }
> > > }
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---