【问题标题】:How to avoid selecting last item from autocompletetextview如何避免从 autocompletetextview 中选择最后一项
【发布时间】:2016-06-29 08:52:19
【问题描述】:

我正在创建简单的应用程序,其中包含名称的AutoCompleteTextView。我想在 AutoCompleteTextView 的最后一项末尾加载一个ImageView,这应该是不可点击/可选择的。

我可以在最后一个列表项之后显示ImageView 来填充列表但是,我不能让它不可点击/选择。意味着,每次它选择 AutoCompleteTextView 的 EMPTY 字段并设置为 BLANK/EMPTY。

这里是我的getView()方法代码:

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

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (position != (resultList.size() - 1))
            view = inflater.inflate(R.layout.autocomplete_list_item, null);
        else
            view = inflater.inflate(R.layout.autocomplete_google_logo, null);

        if (position != (resultList.size() - 1)) {
            TextView autocompleteTextView = (TextView) view.findViewById(R.id.autocompleteText);
            autocompleteTextView.setText(resultList.get(position).getCityDescription());
        }
        else {
            RelativeLayout imageView = (RelativeLayout) view.findViewById(R.id.rlTop);
            imageView.setClickable(false);
            imageView.setEnabled(false);
        }

        return view;
    }

【问题讨论】:

标签: android android-arrayadapter autocompletetextview


【解决方案1】:

找到解决方案。

感谢@Selvin 的评论。

@Override
    public boolean isEnabled(int position) {
        if (position != resultList.size() - 1)
            return true;
        else
            return false;
    }

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

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (position != (resultList.size() - 1))
            view = inflater.inflate(R.layout.autocomplete_list_item, null);
        else
            view = inflater.inflate(R.layout.autocomplete_logo, null);

            if (position != (resultList.size() - 1)) {
                TextView autocompleteTextView = (TextView) view.findViewById(R.id.autocompleteText);
                autocompleteTextView.setText(resultList.get(position).getName());
            } else {
                RelativeLayout imageView = (RelativeLayout) view.findViewById(R.id.rlTop);
            }

        return view;
    }

【讨论】:

    【解决方案2】:

    尝试在该视图上设置onTouchListener,在onTouch() 中什么也不做,只返回true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      • 2016-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多