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.
public class MyCustomView : Java.Lang.Object, SimpleCursorAdapter.IViewBinder
{
public bool SetViewValue(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;
return true;
}
else
{
// cb.Checked = false; //in case you want to make it (uncheck)
return true;
}
// For others, we simply return false so that the default binding
// happens.
}
return true;
}
void cb_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...:)
public class MyCustomView:Java.Lang.Object, SimpleCursorAdapter.IViewBinder
{
public bool SetViewValue (View view, Android.Database.ICursor cursor, int i)
{
if (view.Id == Resource.Id.ListRow1) {
int val = cursor.GetInt (i);
TextView txt = (TextView)view;
txt.Text = val.ToString ();
}
if (view.Id == Resource.Id.ListRow2) {
string val1 = cursor.GetString (i);
TextView txt = (TextView)view;
txt.Text = val1;
}
if (view.Id == Resource.Id.ListRow3)
{
// If the column is IS_STAR then we use custom view.
int is_val = cursor.GetInt (i);
CheckBox cb = (CheckBox) view;
if (is_val != 0)
{
// set the visibility of the view to GONE
cb.Checked = true;
return true;
}
else
{
cb.Clickable = false;
return true;
}
// For others, we simply return false so that the default binding
// happens.
}
return true;
}
Post a Comment for "Set The Checkbox If The Db Table Value Is 1 In Xamarin.android"