【问题标题】:ArrayAdapter Error阵列适配器错误
【发布时间】:2013-03-16 05:41:59
【问题描述】:

您好,我正在尝试实现自定义适配器。我收到以下错误:

03-16 05:23:22.003: E/AndroidRuntime(316): FATAL EXCEPTION: main
03-16 05:23:22.003: E/AndroidRuntime(316): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView

这就是我尝试填充我的 ListView 的方式:

    CustomListViewAdapter adapter = new CustomListViewAdapter(context, R.layout.list_item, rowItems);

这是我得到错误的地方。

我在网上看到很多答案说你需要传入一个TextView,但我希望每一行都有一个图像和两个TextView。我正在关注本教程 http://theopentutorials.com/tutorials/android/listview/android-custom-listview-with-image-and-text-using-arrayadapter/ 并且他们的自定义布局工作正常,它不会抱怨。我对每一行都使用了他们在教程中使用的相同自定义布局。为什么我在抱怨

【问题讨论】:

    标签: android-layout listview custom-adapter


    【解决方案1】:

    在您的代码中检查以下一项

    public class CustomListViewAdapter extends ArrayAdapter<RowItem>

    你写过 RowItem 吗?您可能忘记将ArrayAdapter<String> 更改为ArrayAdapter<RowItem>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-30
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      相关资源
      最近更新 更多