public void setListViewHeightBasedOnChildren(ListView listView) { ListViewAdapter listAdapter = (ListViewAdapter)listView.Adapter; if (listAdapter == null) { return; } int desiredWidth = View.MeasureSpec.MakeMeasureSpec(listView.Width, MeasureSpecMode.Unspecified); int heightMeasureSpec = View.MeasureSpec.MakeMeasureSpec(ViewGroup.LayoutParams.WrapContent, MeasureSpecMode.Exactly); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.Count; i++) { view = listAdapter.GetView(i, view, listView); if (i == 0) { view.LayoutParameters = new ViewGroup.LayoutParams(desiredWidth, WindowManagerLayoutParams.WrapContent); } view.Measure(desiredWidth, heightMeasureSpec); totalHeight += view.MeasuredHeight; } ViewGroup.LayoutParams params1 = listView.LayoutParameters; params1.Height = totalHeight + (listView.DividerHeight * (listAdapter.Count - 1)); listView.LayoutParameters = params1; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs; //var tab = this.ActionBar.NewTab(); //tab.SetText("Location"); ////tab.SetIcon(Resource.Drawable.ic_tab_white); //tab.TabSelected += delegate (object sender, ActionBar.TabEventArgs e) { // e.FragmentTransaction.Add(Resource.Id.fragmentContainer, // new LocationFragment()); //}; //this.ActionBar.AddTab(tab); // Set our view from the "main" layout resource SetContentView(Resource.Layout.WineStores); // Create your application here Button btnWall = FindViewById <Button>(Resource.Id.btnWall); Button btnPP = FindViewById <Button>(Resource.Id.btnPP); Button btnSec = FindViewById <Button>(Resource.Id.btnSec); btnWall.Click += (sender, e) => { var intent = new Intent(this, typeof(EnoListing)); storeName.Add("Wall"); intent.PutStringArrayListExtra("storeName", storeName); StartActivity(intent); }; btnPP.Click += (sender, e) => { var intent = new Intent(this, typeof(EnoListing)); storeName.Add("Secaucas"); intent.PutStringArrayListExtra("storeName", storeName); StartActivity(intent); }; btnSec.Click += (sender, e) => { var intent = new Intent(this, typeof(EnoListing)); storeName.Add("Point Pleasant"); intent.PutStringArrayListExtra("storeName", storeName); StartActivity(intent); }; ListView wineList = FindViewById <ListView>(Resource.Id.wineList); List <Wine> myArr = SampleData(); ListViewAdapter adapter = new ListViewAdapter(this, myArr); wineList.Adapter = adapter; setListViewHeightBasedOnChildren(wineList); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.EnoListing); var storeName = Intent.Extras.GetStringArrayList("storeName") ?? new string[0]; TextView txtStoreName = FindViewById <TextView>(Resource.Id.txtStoreName); txtStoreName.Text = "Welcome to " + storeName[0] + " store !!!"; ListView wineList = FindViewById <ListView>(Resource.Id.wineList); myArr = SampleData(); ListViewAdapter adapter = new ListViewAdapter(this, myArr); wineList.Adapter = adapter; //wineList.ItemClick += WineList_ItemClick; wineList.ItemClick += new EventHandler <AdapterView.ItemClickEventArgs>(WineList_ItemClick); }