请检查此编辑的代码..它的工作,但不显示数据库数据..检查框越来越滴答,但其他2列r打印为ID和日期..我的setviewvalue方法没有得到什么错..设置复选框,如果数据库表值是1 xamarin.android
protected override void OnCreate (Bundle SaveInstace)
{
base.OnCreate (SaveInstace);
SetContentView (Resource.Layout.ListView_layout);
ActionBar.SetDisplayHomeAsUpEnabled (true);
//Gets ListView object instance
Database sqldb1 = ((GlobalClass)this.Application).sqldb;
listItems = FindViewById<ListView> (Resource.Id.listItems);
GetCursorView();
}
void GetCursorView()
{
Database sqldb1 = ((GlobalClass)this.Application).sqldb;
Android.Database.ICursor sqldb_cursor = sqldb1.GetRecordCursor();
if (sqldb_cursor != null)
{
sqldb_cursor.MoveToFirst();
string[] from = new string[] {"_id","date","Value"};
int[] to = new int[] {
Resource.Id.ListRow1,
Resource.Id.ListRow2,
Resource.Id.ListRow3
};
//Creates a SimplecursorAdapter for ListView object
SimpleCursorAdapter sqldb_adapter = new SimpleCursorAdapter (this, Resource.Layout.record_view, sqldb_cursor, from, to);
sqldb_adapter.ViewBinder = new MyCustomView();
listItems.Adapter = sqldb_adapter;
}
else
{
}
}
public class MyCustomView:Java.Lang.Object, SimpleCursorAdapter.IViewBinder
{
public bool SetViewValue (View view, Android.Database.ICursor cursor, int i)
{
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
{
return true;
}
// For others, we simply return false so that the default binding
// happens.
}
return true;
}
}
请人帮我 –
看看这个,可能会有帮助 http://stackoverflow.com/ a/12883426 – RIYAZ
感谢您的重播..我会通过它。 –