可是5-2的视频里没有用构造方法也能显示listView,宽高的话我让activity只显示一个listview也还是没显示
附上activity部分代码,求老师帮忙检查下
private GridView gridView;
private ListView listView;
private List<Map<String,Object>> list=new ArrayList<>();
private String[] from={"img","text"};
private int[] to={R.id.grid_img,R.id.grid_txt};
private List<JsonB> jsonlist=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initData();
initView();
}
private void initData() {
String[] texts={"飞机","车票","汽车","蛋糕","美食","手表","电脑","手机"};
int[] imgs={R.mipmap.fly1, R.mipmap.car,
R.mipmap.autombile1, R.mipmap.cake,
R.mipmap.food, R.mipmap.watch,
R.mipmap.cp, R.mipmap.phone};
for (int i=0;i<8;i++){
Map<String,Object> map=new HashMap<>();
map.put("img",imgs[i]);
map.put("text",texts[i]);
list.add(map);
}
//解析Json获取数据源
parseByJSONObject();
}
private void initView() {
gridView=(GridView)this.findViewById(R.id.gridView);
gridView.setAdapter(new SimpleAdapter(MainActivity.this,list,R.layout.grid_item,from,to));
listView=(ListView)this.findViewById(R.id.listView);
MyAdapter adapter=new MyAdapter(MainActivity.this,jsonlist);
listView.setAdapter(adapter);
}
2020-03-12 17:35:17
jsonlist各对象的属性值呢?你在MyAdapter adapter=new MyAdapter(MainActivity.this,jsonlist);的前一行,遍历一下jsonlist,并且把各对象的属性值输出 一下。
2020-03-12 17:54:56
遍历不了。。。试了while和for循环,循环好像不执行,Log没有输出信息,在循环内部打了断点就好像没打一样
2020-03-12 18:48:57
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星