我是C#的初学者,我有一个xamarin.android项目,我想查看我的表的数据网格视图。无法在gridview(C#)中查看sqlite表格数据,System.Collections.Generic.List
使用此代码为我的活动:
public class MenuFoodActivity : Activity
{
string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "HotelDb.db3");
GridView gv;
ArrayAdapter adapter;
JavaList<String> tvShows = new JavaList<string>();
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.MenuFood);
gv = FindViewById<GridView>(Resource.Id.gridViewMenu);
adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, tvShows);
Retrieve();
}
private void Retrieve()
{
var db = new SQLiteConnection(dpPath);
var data = db.Table<FoodTable>();
var data1 = (from values in data
select new FoodTable
{
Shenase = values.Shenase,
Types = values.Types,
Names = values.Names,
Costs = values.Costs
}).ToList<FoodTable>();
tvShows.Add(data1);
if (tvShows.Size() > 0)
{
gv.Adapter = adapter;
}
else
{
Toast.MakeText(this, "not found.", ToastLength.Short).Show();
}
}
}
而这一次是axml文件
<GridView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="200dip"
android:id="@+id/gridViewMenu"
android:background="#aaa"
android:layout_marginTop="10dip" />
的问题是,当我调试项目现场“DATA1”有数据和if语句的结果是对的,但行
gv.Adapter = adapter;
不起作用,所以我收到这行代替获取我的数据。
为什么使用JavaList?将它列入列表 tvShows = new List ();从使用System.Collections.Generic; –
Merian
我得到这个错误:**无法从'System.Collections.Generic.List转换为'System.Collections.Generic.IEnumerable **,在这一行:'tvShows.Add(data1) ;'@美利安 –
tbp