2017-10-06 147 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); 
}