Xamarin.Android 关于GridView 的正确使用方式
https://blog.csdn.net/qq_35504350/article/details/78189004
这个是重点
-
JavaList
string, object>> data_list = null;//一定要用javalist不能用IList JavaDictionarymap = new JavaDictionary ();
如果你使用的C# 自带的List 会出现重复点击的问题
Dictionary
如果使用的是这个,那么会加载不出来菜单
JavaListstring, object>> menuDatas = new JavaList string, object>>(); foreach (var item in permissionArray) { JavaDictionary<string, object> map = new JavaDictionary<string, object>(); switch (item) { case "1": map.Add("image", Resource.Drawable.图片); map.Add("text", "文字描述"); break; case "2": map.Add("image", Resource.Drawable.图片); map.Add("text", "文字描述"); break; default: break; } menuDatas.Add(map); } //新建适配器 string[] fromMenu = { "image", "text" }; int[] to = { Resource.Id.Img_MenuIco, Resource.Id.Txt_MenuTitle }; SimpleAdapter listAdapter = new SimpleAdapter(this, menuDatas, Resource.Layout.component_gridview_menu, fromMenu, to); gvMenu.Adapter = listAdapter; gvMenu.ItemClick += GvMenu_ItemClick;
private void GvMenu_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { switch (e.Position) { case 1: GridViewItemClick<要打开的页面类>(); break; case 2: GridViewItemClick<要打开的页面类>(); break; default: new AlertDialog.Builder(this) .SetMessage("该功能还在开发中...") .Show(); break; } }
private void GridViewItemClick() where T : Activity { StartNewActivity (this, Resource.Animation.activity_fade_in, Resource.Animation.activity_fade_out, false, null); }
public void StartNewActivity(Context ctext,int enterAnim, int exitAnim, bool isFinish, Bundle mBundle) where T : Activity { var typeActivity = typeof(T); Log.Debug("打开新页面", _context + "" + typeActivity); Intent mIntent = new Intent(ctext, typeActivity); if (mBundle != null) { mIntent.PutExtras(mBundle); } StartActivity(mIntent); OverridePendingTransition(enterAnim, exitAnim); if (isFinish) { Finish(); } }