2017-10-06 146 views
0

我得到这个错误:阵列适配器构造不适用

Error:(31, 9) error: no suitable constructor found for ArrayAdapter(Activity,int,List<UserTreeData>) 
    constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable 
    (argument mismatch; List<UserTreeData> cannot be converted to int) 
    constructor ArrayAdapter.ArrayAdapter(Context,int,UserTreeInputData[]) is not applicable 
    (argument mismatch; List<UserTreeData> cannot be converted to UserTreeInputData[]) 
    constructor ArrayAdapter.ArrayAdapter(Context,int,List<UserTreeInputData>) is not applicable 
    (argument mismatch; List<UserTreeData> cannot be converted to List<UserTreeInputData>)  

这是我的课

package com.example.pradnyanand.thetree; 

import android.app.Activity; 
import android.content.Context; 
import android.support.annotation.NonNull; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.TextView; 

import java.util.List; 

import static com.example.pradnyanand.thetree.R.layout.list_layout; 

public class TreeWeekDataList extends ArrayAdapter<UserTreeInputData> { 

    private Activity context; 
    private List<UserTreeData> treeDatasList; 

    public TreeWeekDataList(Activity context, List<UserTreeData> treeDatasList) { 

    super(context, R.layout.list_layout, treeDatasList); 

    this.context = context; 
    this.treeDatasList = treeDatasList; 

    } 

    @NonNull 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
    LayoutInflater inflater = context.getLayoutInflater(); 
    View listViewItem = inflater.inflate(list_layout, null, true); 

    TextView dateOfPlantation = (TextView) listViewItem.findViewById(R.id.displayPlanatationDate); 
    TextView placeOfPlantation = (TextView) listViewItem.findViewById(R.id.displayPlantationPlace); 
    TextView typeOfTree = (TextView) listViewItem.findViewById(R.id.displayTreeType); 

    UserTreeData trees = treeDatasList.get(position); 

    dateOfPlantation.setText(trees.getDateOfPlanation()); 
    placeOfPlantation.setText(trees.getPlaceOfPlanation()); 
    typeOfTree.setText(trees.getTypeOfTree()); 

    return listViewItem; 
    } 
} 

回答

0

试试这个,超方法将数组作为参数就不一一列举。

private UserTreeData[] treeDatasList; 

public TreeWeekDataList(Activity context, UserTreeData[] treeDatasList) { 
    super(context, R.layout.list_layout, treeDatasList); 

    this.context = context; 
    this.treeDatasList = treeDatasList; 

} 
0

从错误:

no suitable constructor found for ArrayAdapter(Activity,int,List<UserTreeData>) 

您需要创建由一个ArrayAdapter需要一个匹配的构造函数,像这样:

public TreeWeekDataList(Context context, int resourceId, List<UserTreeData> treeDatasList) { 
    super(context, resourceId, treeDatasList); 

    this.context = context; 
    this.treeDatasList = treeDatasList; 
} 

public TreeWeekDataList(Context context, List<UserTreeData> treeDatasList) { 
    super(context, 0, treeDatasList); 
}