Xamarin控件使用之GridView

[Activity(Label = "MainGridViewActivity", LaunchMode = LaunchMode.SingleTop)]//设置Activity启动模式
public class MainGridViewActivity : Activity
{
private GridView gview;
JavaList<IDictionary<string, object>> data_list = null;//一定要用javalist不能用IList
IDictionary<string, object> Map = null;
private SimpleAdapter adapter;
// 图片封装为一个数组
private int[] icon = { Resource.Drawable.Icon_agree , Resource.Drawable.icon_graphic,
Resource.Drawable.icon_roll,Resource.Drawable.Icon_semifin, Resource.Drawable.Icon_bg};
private string[] iconName = { "审批", "报表", "成品","半成品", "报工" };
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.MainGridView_layout); 

gview = FindViewById<GridView>(Resource.Id.gridView1);
//新建List
data_list = new JavaList<IDictionary<string, object>>();//一定要用javalist不能用List 
//获取数据
getData();
//新建适配器
string[] from = { "image", "text" };
int[] to = { Resource.Id.imagegViewMain, Resource.Id.textgViewMain };
adapter = new SimpleAdapter(this, data_list, Resource.Layout.gViewMainItem, from, to);
//配置适配器
gview.Adapter = adapter;

//GridView 的itemclick
gview.ItemClick += gview_ItemClick;//给GridView单元格加点击事件,类似java开发中的监听。
}
private JavaList<IDictionary<string, object>> getData()
{
//cion和iconName的长度是相同的,这里任选其一都可以
for (int i = 0; i < icon.Length; i++)
{
Map = new JavaDictionary<string, object>();
Map.Add("image", icon[i]);
Map.Add("text", iconName[i]);
data_list.Add(Map);
}
return data_list;
}
private void gview_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
switch (e.Position)
{
case 0://审批请求
{
var intent = new Intent(this, typeof(ApprovalActivity));
StartActivity(intent);
}
break;
case 1:
{
var intent = new Intent(this, typeof(GraphicMain));
StartActivity(intent); 
}
break;
case 2:
{
var intent = new Intent(this, typeof(FinishGoodList));
StartActivity(intent);
}
break;
case 3:
{
var intent = new Intent(this, typeof(SemiFinishedGoodsList));
StartActivity(intent);
}
break;
case 4:
{
var intent = new Intent(this, typeof(SubMachineActivity));
StartActivity(intent);
}
break;
default:
new AlertDialog.Builder(this)
.SetMessage("该功能还在开发中...")
.Show();
break;
}
}
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值