我是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