Monday, July 1, 2019

c# - GridView doesn't display data

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 tvShows = new JavaList();


protected override void OnCreate(Bundle savedInstanceState)

{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.MenuFood);
gv = FindViewById(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();
var data1 = (from values in data
select new FoodTable
{
Shenase = values.Shenase,
Types = values.Types,
Names = values.Names,
Costs = values.Costs


}).ToList();

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:



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 tvShows = new List();
JavaList tvShows = new JavaList();
JavaList tvShows = new JavaList();


but they didn't work for me.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...