I'm a beginner in C# and Xamarin. I have this code but I don't know what's wrong with it, that doesn't display data in gridview.
this is the code of 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" />
every thing seems fine and I can enter to the if
statment but there's nothing in my gridview. Anyone knows what's the problem with this code?
Thanks beforehand.
I've tried to use
List<FoodTable> tvShows = new List<FoodTable>();
JavaList<FoodTable> tvShows = new JavaList<FoodTable>();
JavaList<String> tvShows = new JavaList<String>();
but they didn't work for me.