my code review
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了my code review相关的知识,希望对你有一定的参考价值。
1 class ListDeviceAdapter extends BaseAdapter 2 { 3 ChildListView childlist = null; 4 private Context mContext; 5 private List<Map<String, Object>> mDeviceData; // 设备信息集合 6 7 public ListDeviceAdapter(Context context, List<Map<String, Object>> listItems) 8 { 9 this.mContext = context; 10 this.mDeviceData = listItems; 11 System.out.println("-- ListDeviceAdapter is running...--"); 12 } 13 14 @Override 15 public int getCount() 16 { 17 return 0;//return mDeviceData.size();//首先回调getCount()方法,根据其值来决定是否回调getView() 18 } 19 20 @Override 21 public Object getItem(int position) 22 { 23 return mDeviceData.get(position); 24 } 25 26 @Override 27 public long getItemId(int position) 28 { 29 return 0; 30 } 31 32 @Override 33 public View getView(int position, View convertView, ViewGroup parent) 34 { 35 System.out.println("-- getView is running...--"); 36 if (convertView == null) 37 { 38 System.out.println("-- list is running...--"); 39 childlist = new ChildListView(); 40 convertView = LayoutInflater.from(mContext).inflate(R.layout.listview_control, null); 41 childlist.mDeviceType = (ImageButton) convertView.findViewById(R.id.list_btn_device_type); 42 childlist.mDeviceName = (TextView) convertView.findViewById(R.id.list_text_device_name); 43 childlist.mDeviceControl = (ImageButton) convertView.findViewById(R.id.list_btn_device_type); 44 convertView.setTag(childlist); 45 } else 46 { 47 childlist = (ChildListView) convertView.getTag(); 48 } 49 50 childlist.mDeviceType.setBackgroundResource(R.drawable.device_light); 51 childlist.mDeviceName.setText(mDeviceData.get(0).get("title").toString()); 52 childlist.mDeviceControl.setBackgroundResource(R.drawable.device_curtain); 53 54 childlist.mDeviceType.setOnClickListener(new OnClickListener() 55 { 56 public void onClick(View v) 57 { 58 59 } 60 }); 61 childlist.mDeviceControl.setOnClickListener(new OnClickListener() 62 { 63 public void onClick(View v) 64 { 65 66 } 67 }); 68 69 return convertView; 70 } 71 72 class ChildListView 73 { 74 ImageButton mDeviceType; 75 TextView mDeviceName; 76 ImageButton mDeviceControl; 77 } 78 }
发现自定义Adapter先是回调的getCount()方法,起初返回的是空
以上是关于my code review的主要内容,如果未能解决你的问题,请参考以下文章