数组适配器构造函数不适用



我正在遇到此错误:

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;
  }
}

来自错误:

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

您需要创建一个阵列adapter所需的匹配构造函数,类似的东西:

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);
}

尝试一下,超级方法将数组作为参数不列表。

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

最新更新