本文实例为大家分享了Android自定义输入框提示的具体代码,供大家参考,具体内容如下
这是系统提供的一个控件:AutoCompleteTextView
<AutoCompleteTextView android:layout_marginLeft="20dp" android:id="@+id/name_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="6" android:completionThreshold="1" android:textSize="15sp" android:maxLength="10" android:singleLine="true" android:paddingBottom="4dp" android:background="@null" android:hint="请输入姓名"/>
但是我们想在item的布局中加入其他东西怎么办?这样我们只能自己定义适配器,首先先看看AutoCompleteTextView需要的适配器的类型
查看AutoCompleteTextView的setAdapter()方法的源码如下:
public <T extends ListAdapter & Filterable> void setAdapter(T adapter) { if (mObserver == null) { mObserver = new PopupDataSetObserver(this); } else if (mAdapter != null) { mAdapter.unregisterDataSetObserver(mObserver); } mAdapter = adapter; if (mAdapter != null) { //noinspection unchecked mFilter = ((Filterable) mAdapter).getFilter(); adapter.registerDataSetObserver(mObserver); } else { mFilter = null; } mPopup.setAdapter(mAdapter); }
自定义适配器核心代码:
private PoiKeyTipListAdapter poiKeyTipListAdapter; poiKeyTipListAdapter = new PoiKeyTipListAdapter(this); nameEdit.setAdapter(poiKeyTipListAdapter); nameEdit.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void> public class PoiKeyTipListAdapter extends BaseAdapter implements Filterable { private List<SendNameBean.DataBean> stringArrayList ; private Context context; private>![]()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
Android自定义输入框提示功能
扫一扫手机访问
