码迷,mamicode.com
首页 > 其他好文 > 详细

my code review

时间:2017-03-24 15:59:37      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:private   str   type   extend   device   集合   long   string   style   

 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

标签:private   str   type   extend   device   集合   long   string   style   

原文地址:http://www.cnblogs.com/mlpzxf/p/6611597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!