AutoCompleteTextView阵列适配器混合位置和项目

时间:2020-05-29 23:42:54

标签: android-studio android-arrayadapter android-adapter autocompletetextview custom-arrayadapter

我有一个带有普通自定义适配器的标准自动完成文本视图。但是,正如您在照片中看到的那样,Android将小时数与多个位置相关联(其中一些错误)。如果您看一看,您会发现适配器已将其正确地缩小为两个选择。但是,“ ola”一小时应该没有,而“ polonis”一小时却正确。发生的错误是“ ola”上的小时数是“ polonis”上的小时数,而本来应该没有。以下两个信息可能会有所帮助:

首先,我使用了多个Log.d方法,错误的时间总是与不同于该职位的notev2相关联。其次,如果我添加一行文本以该适配器文本视图填充一个点,问题就会消失。

enter image description here

enter image description here

这是我在getView上的适配器代码

@Override
    public View getView(int position, View view, @NonNull ViewGroup parent) {

        if (view == null) {
            view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.autocompletelayout, parent, false);
        }

        Notev2 notev2 = getItem(position);

        TextView titlePlace = (TextView) view.findViewById(R.id.autocomplete_title);
        titlePlace.setText(notev2.getTitle_v2());

        String slocation = "" + notev2.getLocation_v2();
        if (slocation.contains("zioiu"))
            slocation = "";
        TextView locationPlace = (TextView) view.findViewById(R.id.autocomplete_location);
        locationPlace.setText(slocation);

        TextView hoursPlace = (TextView) view.findViewById(R.id.autocomplete_openingHours);

        if (!day.equals("Hello")) {
            String[] openingHoursv2 = {notev2.getOpening_hours_1_v2(), notev2.getOpening_hours_2_v2(), notev2.getOpening_hours_3_v2()};
            List<String> allOpeningHours = new ArrayList<>(Arrays.asList(notev2.getOpening_hours_1_v2()
                    , notev2.getOpening_hours_2_v2(),
                    notev2.getOpening_hours_3_v2()));
            for (String openingHours : openingHoursv2) {
                if (!openingHours.equals("")) {
                    Log.d("NoNoteAdapter", openingHours + notev2.getTitle_v2() + "  " + position);
                    if (getBelongs(day, openingHours)) {
                        String toAppend = getClockPart(openingHours);
                        if (getOpenVsClosed(toAppend)) hoursPlace.setTextColor(Color.parseColor("#12D529"));
                        else hoursPlace.setTextColor(Color.parseColor("#D80E0E"));
                        hoursPlace.append(toAppend);
                    }
                } else { #if the dotted version
                    hoursPlace.append(.); 
                }
            }
        }


        return view;
    }

0 个答案:

没有答案
相关问题