【问题标题】:There are two errors, I can not solve it(ListView)有两个错误,我解决不了(ListView)
【发布时间】:2016-11-19 13:34:42
【问题描述】:

        

【问题讨论】:

  • 请不要发布代码、XML 或 logcat 输出的屏幕截图。请将所有文本作为文本发布在问题本身中,并详细说明您遇到的问题。
  • getText(a.context) 第一期
  • @dowswin 代码完全不可读。

标签: java android listview gradle


【解决方案1】:

将适配器初始化移到 onCreate 中。您需要使用setAdapter 将适配器设置为ListView。填充数据集arr后调用noftifyDataSetChanged

试试这个代码,

private MyAdapter ma;

onCreate(){
    ...
    setContentView(R.layout.activty_main2);
    lv = (ListView) findViewById(R.id.lv_1);
    ma = new MyAdapter(this, arr);
    lv.setAdapter(ma);
    initData();
}

initData(){
    for(;;){
        ...
        arr.add(n);     
    }
    ma.noftifyDataSetChanged();
}

【讨论】:

    【解决方案2】:

    您在 MyAdapter 中没有任何空白构造函数, 您必须将上下文和 ArrayList 传递给适配器,例如,

    MyAdapter ma = new MyAdapter(Main2Activity.this,arr);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多