我正在创建一个简单的应用程序,其中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;
}
答案 0 :(得分:0)
得到了解决方案。
感谢@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;
}
答案 1 :(得分:-1)
尝试在该视图上设置onTouchListener
,并在onTouch()
中不执行任何操作,只需返回true