主题 : 【代码】得到控件后自定义adapterid实现点击跳转 复制链接 | 浏览器收藏 | 打印
欢迎加入清源的android开发交流群:314230976,加群时请验证:arm,谢谢!
级别: 侠客
UID: 94332
精华: 0
发帖: 72
金钱: 370 两
威望: 74 点
贡献值: 0 点
综合积分: 144 分
注册时间: 2013-07-14
最后登录: 2013-09-25
楼主  发表于: 2013-07-17 16:38

 【代码】得到控件后自定义adapterid实现点击跳转

复制代码
  1. public class DeviceAdapter extends BaseAdapter {
  2. Context context;
  3. List> mList;
  4. LayoutInflater inflater;
  5. public DeviceAdapter(Context context,List> mList){
  6. this.context = context;
  7. this.mList = mList;
  8. inflater = LayoutInflater.from(context);
  9. }
  10. public int getCount() {
  11. // TODO Auto-generated method stub
  12. return mList.size();
  13. }
  14. public Object getItem(int position) {
  15. // TODO Auto-generated method stub
  16. return mList.get(position);
  17. }
  18. public long getItemId(int position) {
  19. // TODO Auto-generated method stub
  20. return 0;
  21. }
  22. public View getView(int position, View convertView, ViewGroup parent) {
  23. View view = inflater.inflate(R.layout.devicelistitem,null);
  24. ImageView device_icon = (ImageView) view.findViewById(R.id.device_icon);
  25. device_icon.setBackgroundResource((Integer) mList.get(position).get("device_icon"));
  26. TextView  device_name = (TextView) view.findViewById(R.id.device_name);
  27. device_name.setText(mList.get(position).get("device_name").toString());
  28. TextView device_setting = (TextView) view.findViewById(R.id.device_setting);
  29. device_setting.setText(mList.get(position).get("device_setting").toString());
  30. device_setting.setOnClickListener(new View.OnClickListener() {
  31. public void onClick(View v) {
  32. View view1 = inflater.inflate(R.layout.devicesetting, null);
  33. Builder builder = new AlertDialog.Builder(context);
  34. builder.setTitle("其他功能");
  35. builder.setView(view1);
  36. builder.create().show();
  37. TextView timesetting = (TextView) view1.findViewById(R.id.timesetting);
  38. TextView timedelete = (TextView) view1.findViewById(R.id.timedelet);
  39. timesetting.setOnClickListener(new View.OnClickListener() {
  40. public void onClick(View v) {
  41. Intent intent = new Intent();
  42. intent.setClass(context, SmartPowerActivity.class);
  43. context.startActivity(intent);
  44. }
  45. });
  46. }
  47. });
  48. return view;
  49. }
欢迎加入android开发交流群,群号是:314230976