ArrayAdapter():找不到合适的构造函数

时间:2014-10-28 23:26:21

标签: java arraylist android-arrayadapter android-adapter

我从Android编程开始。当我收到以下错误时,我无法编译我的程序:

Error: no suitable constructor found for ArrayAdapter()

这是我的个人适配器:

public class StationListAdapter extends ArrayAdapter<Station> {

    private ArrayList<Station> stations;
    private Context context;
    private int resource;
    LayoutInflater layoutInflater;

    //Constructor - args : (context, resourceId, ArrayList<MyClass>)
    public StationListAdapter(Context context, int resource, ArrayList<Station> stations) {

        this.context = context;
        this.resource = resource;
        this.stations = stations;
        layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

以下是适配器实例的部分:

public void onArrayListReady(ArrayList<Station> stations) {
    TextView textView = (TextView) this.view.findViewById(R.id.fragment_list_textview);
    ListView listView = (ListView) this.view.findViewById(R.id.fragment_list_stations_list);
    adapter = new StationListAdapter(getActivity(), R.layout.fragment_list_row, stations);
    listView.setAdapter(adapter);
}

1 个答案:

答案 0 :(得分:1)

您需要从构造函数中调用超级构造函数才能正确初始化适配器。

相关问题