I'm beginner in C#, I have a xamarin.android project, and I want to view the data of my table in a gridview.
Using this code for my activity:
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();
}
}
}
and this one is for axml file
<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" />
The problem is that when I'm debugging the project the field 'data1' has the data and the result of if statement is true, but the line
gv.Adapter = adapter;
does not work so I recieve this line instead of getting my data.
System.Collections.Generic.List[MainAppHotelXamarin.FoodTable]