这些子项内容怎么是空的?
 public class MainActivity extends Activity {

    private ListView lv; 
    private List<Map<String, Object>> data; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        lv = (ListView)findViewById(R.id.lv); 
        //获取将要绑定的数据设置到data中 
        data = selectRoadsStaus(); 
        MyAdapter adapter = new MyAdapter(this); 
        lv.setAdapter(adapter); 
    } 

    public List<Map<String, Object>> selectRoadsStaus(){
        Map<String,Object> map = new HashMap<String,Object>();
        List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
        for(int i = 1; i <= 5 ; i++){
            Map<String,Object> map1 = new HashMap<String,Object>();
            map1.put("num",String.valueOf(i));
            if("1".equals(String.valueOf(i))){
                map1.put("bak",0xff1A78FE);//map.get(String.valueOf(i))
            }else if("2".equals(String.valueOf(i))){
                map1.put("bak", Color.alpha(0xff9FC95D));//map.get(String.valueOf(i))
            }else if("3".equals(String.valueOf(i))){
                map1.put("bak", Color.alpha(0xffFFC95C));//map.get(String.valueOf(i))
            }else if("4".equals(String.valueOf(i))){
                map1.put("bak", 0xffE16567);//map.get(String.valueOf(i))
            }else if("5".equals(String.valueOf(i))){
                map1.put("bak", Color.alpha(0xffE60513));//map.get(String.valueOf(i))
            }
            list.add(map1);
        }
        System.out.print(list);
        return list;
    }


    //ViewHolder静态类 
    static class ViewHolder 
    { 
        public TextView num; 
        public TextView bak; 
    } 

    public class MyAdapter extends BaseAdapter 
    {     
        private LayoutInflater mInflater = null; 
        private MyAdapter(Context context) 
        { 
            //根据context上下文加载布局,
            this.mInflater = LayoutInflater.from(context); 
        } 

        @Override 
        public int getCount() { 
            //How many items are in the data set represented by this Adapter. 
            //在此适配器中所代表的数据集中的条目数 
            return data.size(); 
        } 

        @Override 
        public Object getItem(int position) { 
            // Get the data item associated with the specified position in the data set. 
            //获取数据集中与指定索引对应的数据项 
            return position; 
        } 

        @Override 
        public long getItemId(int position) { 
            //Get the row id associated with the specified position in the list. 
            //获取在列表中与指定索引对应的行id 
            return position; 
        } 

        //Get a View that displays the data at the specified position in the data set. 
        //获取一个在数据集中指定索引的视图来显示数据 
        @Override 
        public View getView(int position, View convertView, ViewGroup parent) { 
            ViewHolder holder = null; 
            //如果缓存convertView为空,则需要创建View 
            if(convertView == null) 
            { 
                holder = new ViewHolder(); 
                //根据自定义的Item布局加载布局 
                convertView = mInflater.inflate(R.layout.list_item, null);  
                holder.num = (TextView)convertView.findViewById(R.id.tv); 
                holder.bak = (TextView)convertView.findViewById(R.id.info); 
                //将设置好的布局保存到缓存中,并将其设置在Tag里,以便后面方便取出Tag 
                convertView.setTag(holder); 
            }else 
            { 
                holder = (ViewHolder)convertView.getTag(); 
            } 
           // holder.img.setBackgroundResource((Integer)data.get(position).get("img")); 
            holder.num.setText((String)data.get(position).get("title")); 
            holder.bak.setText((String)data.get(position).get("info")); 

            return convertView; 
        } 

    } 
}

图片说明

2个回答

holder.num.setText((String)data.get(position).get("title"));
holder.bak.setText((String)data.get(position).get("info"));

selectRoadsStaus 这个方法在构造map的时候,根本没有用 title info 这两个key。那绘制list的时候,怎么从map里面获取title和info

holder.num.setText((String)data.get(position).get("title"));
下一个断点,调试下这里

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!