Skip to content Skip to sidebar Skip to footer

Set The Checkbox If The Db Table Value Is 1 In Xamarin.android

Please check this edited code.. its working but not showing the data of database..check box is getting tick but other 2 columns r printing as id and date..Not getting whats wrong i

Solution 1:

Looks good, just added checkbox click, have a look.

publicclassMyCustomView : Java.Lang.Object, SimpleCursorAdapter.IViewBinder
{

    publicboolSetViewValue(View view, Android.Database.ICursor cursor, int i)
    {
        if (view.Id == Resource.Id.action_bar)
        {
            // If the column is IS_STAR then we use custom view.int is_val = cursor.GetInt(i);
            CheckBox cb = (CheckBox)view;
            cb.Click += cb_Click;
            if (is_val != 0)
            {
                // set the visibility of the view to GONE
                cb.Checked = true;
                returntrue;
            }
            else
            {
                // cb.Checked = false; //in case you want to make it (uncheck)returntrue; 
            }
            // For others, we simply return false so that the default binding// happens.

        }
        returntrue;
    }

    voidcb_Click(object sender, EventArgs e)
    {
        //Handle checkbox click because value will be cahnge while clicking on checkbox
    }
}

Solution 2:

this code worked me thank you...:)

publicclassMyCustomView:Java.Lang.Object, SimpleCursorAdapter.IViewBinder
            {

                public bool SetViewValue(View view, Android.Database.ICursor cursor, int i)
                {
                    if (view.Id == Resource.Id.ListRow1) {
                        intval= cursor.GetInt (i);
                        TextViewtxt= (TextView)view;
                        txt.Text = val.ToString ();
                    }
                    if (view.Id == Resource.Id.ListRow2) {
                        stringval1= cursor.GetString (i);
                        TextViewtxt= (TextView)view;
                        txt.Text = val1;
                    }
                    if (view.Id == Resource.Id.ListRow3) 

                    { 
                        // If the column is IS_STAR then we use custom view.intis_val= cursor.GetInt (i);
                        CheckBoxcb= (CheckBox) view;
                        if (is_val != 0)
                        {
                            // set the visibility of the view to GONE

                            cb.Checked = true;
                            returntrue;
                    } 
                        else
                    {
                            cb.Clickable = false;
                        returntrue;
                    }
                    // For others, we simply return false so that the default binding// happens.

                }
                    returntrue;
           }

Post a Comment for "Set The Checkbox If The Db Table Value Is 1 In Xamarin.android"