1个回答
2012-06-05
展开全部
public class MenuAty extends Activity {
/** Called when the activity is first created. */
private NotificationManager mNotificationManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
GridView gv_menu = (GridView) findViewById(R.id.menu_gv);
gv_menu.setAdapter(new MenuAdapter());
}
class MenuAdapter extends BaseAdapter {
String[] ment_str = new String[] { "信息查询", "工作计划", "资料查询", "销售管理",
"申请管理", "培训平台", "系统设置", "数据管理", "退出" };
int[] images = new int[] { R.drawable.menu_01, R.drawable.menu_02,
R.drawable.menu_03, R.drawable.menu_04, R.drawable.menu_05,
R.drawable.menu_06, R.drawable.menu_07, R.drawable.menu_08,
R.drawable.menu_09 };
LayoutInflater inflater = LayoutInflater.from(MenuAty.this);
@Override
public int getCount() {
return ment_str.length;
}
@Override
public Object getItem(int position) {
return ment_str[position];
}
@Override
public long getItemId(int position) {
return 0;
}
public void click(ImageView rb, final Class<? extends Activity> cls) {
rb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MenuAty.this, cls);
startActivity(intent);
}
});
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
ImageView rb = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.menu_item, null);
rb = (ImageView) convertView.findViewById(R.id.rb_menu_btn);
convertView.setTag(rb);
} else {
rb = (ImageView) convertView.getTag();
}
switch (position) {
case 0:
click(rb, Search_InfoAty.class);
break;
case 1:
click(rb, WorkPlayAty.class);
break;
case 2:
click(rb, InformationAty.class);
break;
case 3:
click(rb, SellManagerAty.class);
break;
case 4:
click(rb, ManageApplicationAty.class);
break;
case 5:
click(rb, TrainingAty.class);
break;
case 6:
click(rb, SettingAty.class);
break;
case 7:
click(rb, CleanDataAty.class);
break;
case 8:
rb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ViewHelper.setDialog(MenuAty.this, "退出", null, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
SysUtil su = new SysUtil(MenuAty.this);
su.exit(MenuAty.this);
finish();
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}, "你确定要退出吗?");
}
});
break;
}
rb.setBackgroundResource(images[position]);
rb.setText(ment_str[position]);
return convertView;
}
}
}
这就是一个例子 你可以看看
/** Called when the activity is first created. */
private NotificationManager mNotificationManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
GridView gv_menu = (GridView) findViewById(R.id.menu_gv);
gv_menu.setAdapter(new MenuAdapter());
}
class MenuAdapter extends BaseAdapter {
String[] ment_str = new String[] { "信息查询", "工作计划", "资料查询", "销售管理",
"申请管理", "培训平台", "系统设置", "数据管理", "退出" };
int[] images = new int[] { R.drawable.menu_01, R.drawable.menu_02,
R.drawable.menu_03, R.drawable.menu_04, R.drawable.menu_05,
R.drawable.menu_06, R.drawable.menu_07, R.drawable.menu_08,
R.drawable.menu_09 };
LayoutInflater inflater = LayoutInflater.from(MenuAty.this);
@Override
public int getCount() {
return ment_str.length;
}
@Override
public Object getItem(int position) {
return ment_str[position];
}
@Override
public long getItemId(int position) {
return 0;
}
public void click(ImageView rb, final Class<? extends Activity> cls) {
rb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MenuAty.this, cls);
startActivity(intent);
}
});
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
ImageView rb = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.menu_item, null);
rb = (ImageView) convertView.findViewById(R.id.rb_menu_btn);
convertView.setTag(rb);
} else {
rb = (ImageView) convertView.getTag();
}
switch (position) {
case 0:
click(rb, Search_InfoAty.class);
break;
case 1:
click(rb, WorkPlayAty.class);
break;
case 2:
click(rb, InformationAty.class);
break;
case 3:
click(rb, SellManagerAty.class);
break;
case 4:
click(rb, ManageApplicationAty.class);
break;
case 5:
click(rb, TrainingAty.class);
break;
case 6:
click(rb, SettingAty.class);
break;
case 7:
click(rb, CleanDataAty.class);
break;
case 8:
rb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ViewHelper.setDialog(MenuAty.this, "退出", null, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
SysUtil su = new SysUtil(MenuAty.this);
su.exit(MenuAty.this);
finish();
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}, "你确定要退出吗?");
}
});
break;
}
rb.setBackgroundResource(images[position]);
rb.setText(ment_str[position]);
return convertView;
}
}
}
这就是一个例子 你可以看看
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询