首页 > 解决方案 > Android Multiline autocompletetextview 下拉滚动出现一项错误

问题描述

我为我的 Autocompletetextview android 创建了多行下拉项。在下拉滚动中,只有一两个项目检查附加的屏幕截图。当项目超过 5 项时,应出现下拉菜单中的滚动。对于单个多行项目,因为在滚动被剪切时可以看到滚动完整项目信息。

在此处输入图像描述

在此处输入图像描述

我的项目 XML

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/underline">
    <com.rm.partner.customview.CustomTextView
        android:id="@+id/autoCompleteSpinnerText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="left|center"
        android:maxLines="10"
        android:padding="@dimen/margin_5dp"
        android:scrollHorizontally="false"
        android:textColor="@color/grey_textcolor"
        app:fontName_TextView="@string/FONT_PROXIMANOVALIGHT"/>
</LinearLayout>

自动完成文本视图

<AutoCompleteTextView
             android:id="@+id/select_scheme_spinner"
             android:layout_width="0dp"
             android:layout_height="match_parent"
             android:layout_weight="0.90"
             android:background="@android:color/transparent"
             android:hint="@string/autocomplete_hint"
             android:imeOptions="actionDone"
             android:inputType="none"
             android:overlapAnchor="false"
             android:paddingLeft="@dimen/margin_5dp"
             android:paddingRight="@dimen/margin_5dp"
             android:textColor="@color/grey_textcolor"
             android:textColorHint="@color/grey_textcolor"
             android:textCursorDrawable="@drawable/custom_cursor_grey"
             android:textSize="@dimen/font_12sp"
             android:theme="@style/Widget.AppCompat.AutoCompleteTextView"
             app:fontName_TextView="@string/FONT_PROXIMANOVALIGHT" />

自定义适配器 getView

 @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        try {
            final ViewHolder viewHolder; // view lookup cache stored in tag
            final ClientFolioResponse.ResponseListObjectBean schemeOptionObj = dataSet.get(position);
            final View result;
            if (convertView == null) {
                viewHolder = new ViewHolder();
                LayoutInflater inflater = LayoutInflater.from(getContext());
                convertView = inflater.inflate(R.layout.spiner_item_reft, parent, false);
                viewHolder.schemeName = convertView.findViewById(R.id.autoCompleteSpinnerText);
                result = convertView;
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
                result = convertView;
            }
            if (schemeOptionObj.getFolioNo().length()>0) {
                String schemeNameText = schemeOptionObj.getFolioNo() + "/" + schemeOptionObj.getSchemeName();
                viewHolder.schemeName.setText(schemeNameText);
            } else {
                viewHolder.schemeName.setText(schemeOptionObj.getSchemeName());
            }
            result.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                        InputMethodManager imm = (InputMethodManager) getContext()
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        if (imm != null) {
                            imm.hideSoftInputFromWindow(
                                    view.getApplicationWindowToken(), 0);
                        }
                    }
                    return false;
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

标签: androidmultilineautocompletetextview

解决方案


推荐阅读