Android 未调用微调器getView()的自定义ArrayAdapter

Android 未调用微调器getView()的自定义ArrayAdapter,android,android-arrayadapter,android-spinner,Android,Android Arrayadapter,Android Spinner,自定义阵列适配器有问题。我阅读了堆栈上所有关于它的线程,但仍然无法解决这个问题。我使用了这个问题中的代码(它不起作用,所以我做了一些小改动: 问题是我创建了适配器,并且: 1.getCount显示正确的值(244) 2.未调用getView 3.getDropdown视图也未调用 你能帮我解决这个问题吗 适配器类: public class DishesFilterCustomArrayAdapter extends ArrayAdapter<Dish> { private Lis

自定义阵列适配器有问题。我阅读了堆栈上所有关于它的线程,但仍然无法解决这个问题。我使用了这个问题中的代码(它不起作用,所以我做了一些小改动:

问题是我创建了适配器,并且: 1.getCount显示正确的值(244) 2.未调用getView 3.getDropdown视图也未调用

你能帮我解决这个问题吗

适配器类:

public class DishesFilterCustomArrayAdapter extends ArrayAdapter<Dish> {

private List<Dish> items;
private Context context;
private Activity activity;

public DishesFilterCustomArrayAdapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull List<Dish> objects) {
    super(context, resource, textViewResourceId, objects);
    this.items = objects;
    this.context = context;
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    TextView v = (TextView) super.getView(position, convertView, parent);

    if (v == null) {
        v = new TextView(context);
    }
    v.setTextColor(context.getResources().getColor(R.color.blue_light));
    v.setText(items.get(position).dishName);

    return v;
}

@Override
public Dish getItem(int position) {
    return items.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        v = inflater.inflate(R.layout.payment_mode_payer_item, null);
    }
    TextView lbl = (TextView) v.findViewById(R.id.textViewForAdapter);
    lbl.setTextColor(context.getResources().getColor(R.color.blue_light));
    lbl.setText(items.get(position).dishName);

    return convertView;
}

@Override
public int getCount() {
    return items.size();
}

public List<Dish> getItems() {
    return items;
}
公共类DishesFilterCustomArrayAdapter扩展ArrayAdapter{
私人清单项目;
私人语境;
私人活动;
public DishesFilterCustomArrayAdapter(@NonNull上下文上下文、int资源、int文本视图资源ID、@NonNull列表对象){
超级(上下文、资源、textViewResourceId、对象);
此项=对象;
this.context=上下文;
}
@凌驾
公共视图getDropDownView(int位置、视图转换视图、视图组父视图){
TextView v=(TextView)super.getView(position,convertView,parent);
如果(v==null){
v=新文本视图(上下文);
}
v、 setTextColor(context.getResources().getColor(R.color.blue_light));
v、 setText(items.get(position.dishName);
返回v;
}
@凌驾
公共物品(内部位置){
返回项目。获取(位置);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
LayoutFlater充气机=LayoutFlater.from(上下文);
v=充气机。充气(R.layout.payment\u mode\u Paymer\u item,空);
}
TextView lbl=(TextView)v.findViewById(R.id.textViewForAdapter);
setextcolor(context.getResources().getColor(R.color.blue_light));
lbl.setText(items.get(position.dishName));
返回视图;
}
@凌驾
public int getCount(){
返回items.size();
}
公共列表getItems(){
退货项目;
}
来自片段的代码:

        mDishList = new ArrayList<>();
        mDishList.addAll(getAllDishesSegregatedList(getAllDishesList()));
        mDishesAdapter = new DishesFilterCustomArrayAdapter(getContext(), R.layout.payment_mode_payer_item, R.id.textViewForAdapter, mDishList);
        //mDishesAdapter.add(new Dish(getString(R.string.filter_receipt_history_by_dish_name)));
        dishesFilterSpinner.setAdapter(mDishesAdapter);
mDishList=newarraylist();
addAll(getAllDishesSegregatedList(getAllDishessesList());
mDishesAdapter=new DishesFilterCustomArrayAdapter(getContext(),R.layout.payment\u mode\u payer\u item,R.id.textViewForAdapter,mDishList);
//添加(新盘子(getString(R.string.filter\u receipt\u history\u by\u Dish\u name));
洗碗机过滤器旋转器。设置适配器(mDishesAdapter);

mDishList大小为244,与getCount()值匹配。

问题已解决。第一个错误是我有两个id相同的视图,我将适配器设置为不可见的视图

第二个问题是,我的自定义适配器的代码中有一些错误。我将其发布在下面

public class DishesFilterCustomArrayAdapter extends ArrayAdapter<Dish> {

private List<Dish> items;
private Context context;

public DishesFilterCustomArrayAdapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull List<Dish> objects) {
    super(context, resource, textViewResourceId, objects);
    this.items = objects;
    this.context = context;
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        v = inflater.inflate(R.layout.receipt_history_spinner_item, null);
    }
    TextView lbl = (TextView) v.findViewById(R.id.receiptHistorySpinnerItemTextView);
    lbl.setTextColor(context.getResources().getColor(R.color.blue_light));
    lbl.setText(items.get(position).dishName);

    return v;
}

@Override
public Dish getItem(int position) {
    return items.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        v = inflater.inflate(R.layout.receipt_history_spinner_item, null);
    }
    TextView lbl = (TextView) v.findViewById(R.id.receiptHistorySpinnerItemTextView);
    lbl.setTextColor(context.getResources().getColor(R.color.blue_light));
    lbl.setText(items.get(position).dishName);

    return v;
}

@Override
public int getCount() {
    return items.size();
}

public List<Dish> getItems() {
    return items;
}
公共类DishesFilterCustomArrayAdapter扩展ArrayAdapter{
私人清单项目;
私人语境;
public DishesFilterCustomArrayAdapter(@NonNull上下文上下文、int资源、int文本视图资源ID、@NonNull列表对象){
超级(上下文、资源、textViewResourceId、对象);
此项=对象;
this.context=上下文;
}
@凌驾
公共视图getDropDownView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
LayoutFlater充气机=LayoutFlater.from(上下文);
v=充气机。充气(R.layout.receipt\u history\u spinner\u item,空);
}
TextView lbl=(TextView)v.findViewById(R.id.receiptHistorySpinnerItemTextView);
setextcolor(context.getResources().getColor(R.color.blue_light));
lbl.setText(items.get(position.dishName));
返回v;
}
@凌驾
公共物品(内部位置){
返回项目。获取(位置);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
LayoutFlater充气机=LayoutFlater.from(上下文);
v=充气机。充气(R.layout.receipt\u history\u spinner\u item,空);
}
TextView lbl=(TextView)v.findViewById(R.id.receiptHistorySpinnerItemTextView);
setextcolor(context.getResources().getColor(R.color.blue_light));
lbl.setText(items.get(position.dishName));
返回v;
}
@凌驾
public int getCount(){
返回items.size();
}
公共列表getItems(){
退货项目;
}

Mike.M感谢您的帮助!

问题已解决。第一个错误是我有两个相同id的视图,我将适配器设置为不可见的视图

第二个问题是,我的自定义适配器的代码中有一些错误。我将其发布在下面

public class DishesFilterCustomArrayAdapter extends ArrayAdapter<Dish> {

private List<Dish> items;
private Context context;

public DishesFilterCustomArrayAdapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull List<Dish> objects) {
    super(context, resource, textViewResourceId, objects);
    this.items = objects;
    this.context = context;
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        v = inflater.inflate(R.layout.receipt_history_spinner_item, null);
    }
    TextView lbl = (TextView) v.findViewById(R.id.receiptHistorySpinnerItemTextView);
    lbl.setTextColor(context.getResources().getColor(R.color.blue_light));
    lbl.setText(items.get(position).dishName);

    return v;
}

@Override
public Dish getItem(int position) {
    return items.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
        v = inflater.inflate(R.layout.receipt_history_spinner_item, null);
    }
    TextView lbl = (TextView) v.findViewById(R.id.receiptHistorySpinnerItemTextView);
    lbl.setTextColor(context.getResources().getColor(R.color.blue_light));
    lbl.setText(items.get(position).dishName);

    return v;
}

@Override
public int getCount() {
    return items.size();
}

public List<Dish> getItems() {
    return items;
}
公共类DishesFilterCustomArrayAdapter扩展ArrayAdapter{
私人清单项目;
私人语境;
public DishesFilterCustomArrayAdapter(@NonNull上下文上下文、int资源、int文本视图资源ID、@NonNull列表对象){
超级(上下文、资源、textViewResourceId、对象);
此项=对象;
this.context=上下文;
}
@凌驾
公共视图getDropDownView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
LayoutFlater充气机=LayoutFlater.from(上下文);
v=充气机。充气(R.layout.receipt\u history\u spinner\u item,空);
}
TextView lbl=(TextView)v.findViewById(R.id.receiptHistorySpinnerItemTextView);
setextcolor(context.getResources().getColor(R.color.blue_light));
lbl.setText(items.get(position.dishName));
返回v;
}
@凌驾
公共物品(内部位置){
返回项目。获取(位置);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
LayoutFlater充气机=LayoutFlater.from(上下文);
v=充气机。充气(R.layout.receipt\u history\u spinner\u item,空);
}
TextView lbl=(TextView)v.findViewById(R.id.receiptHistorySpinnerItemTextView);
setextcolor(context.getResources().getColor(R.color.blue_light));
lbl.setText(items.get(position.dishName));
返回v;
}
@凌驾
public int getCount(){
返回items.size();
}
公共列表项目