【问题标题】:Public ArrayAdapter for ListViewListView 的公共 ArrayAdapter
【发布时间】:2013-04-29 09:23:25
【问题描述】:

参考以下代码。我想知道为什么我需要放入一个对象而不是字符串中的所有对象。此代码来自自定义 ListView 适配器。

public ArrayAdapter (Context context, int textViewResourceId, T[] objects)

工作正常

public ListViewAdapter(Context context, String[] first, String[] second, String[] third) {
            super(context, R.layout.listview_item, first);
            this.context = context;
            this.first = first;
            this.second = second;
            this.third = third;
        }

如果我这样做会出错。

public ListViewAdapter(Context context, String[] first, String[] second, String[] third) {
        super(context, R.layout.listview_item, first, second, third);
        this.context = context;
        this.first = first;
        this.second = second;
        this.third = third;
    }

错误:构造函数 ArrayAdapter(Context, int, String[], String[], String[]) 未定义

原文出处

public class ListViewAdapter extends ArrayAdapter<String> {
    Context context;
    String[] first;
    String[] second;
    String[] third;
    LayoutInflater inflater;

    public ListViewAdapter(Context context, String[] first, String[] second, String[] third) {
        super(context, R.layout.listview_item, first);
        this.context = context;
        this.first = first;
        this.second = second;
        this.third = third;
    }

【问题讨论】:

  • super 调用您正在扩展的类的构造函数,如果您查看您提供的链接,您会发现它不存在。

标签: android listview


【解决方案1】:

您应该阅读Java 中inheritance 的原理。你的班级正在扩展ArrayAdapter

如果你看一下,你会发现没有为这个类定义ArrayAdapter(Context, int, String[], String[], String[]) 类型的构造函数。

这就是为什么你不能做super(context, R.layout.listview_item, first, second, third);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多