• 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()方法,起初返回的是空

  • 相关阅读:
    Arduino-串口函数Serial
    声之翼——超声波模块
    Arduino入门教程--课前准备--Arduino驱动安装及1.0 IDE菜单介绍
    光之触角——光敏电阻、光敏二极管、光敏三极管与光照发生器
    reactjs--父组件调用子组件的内部方法(转载)
    React怎么创建.babelrc文件
    第一课 矩阵的行图像与列图像(麻省理工公开课:线性代数)【转载】
    单片机引脚间状态传递(非转载)
    sublime text2卸载和重新安装(转载)
    C语言头文件怎么写?(转载)
  • 原文地址:https://www.cnblogs.com/mlpzxf/p/6611597.html
Copyright © 2020-2023  润新知