国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android編程實現輸入框動態自動提示功能

2019-10-23 18:35:44
字體:
來源:轉載
供稿:網友

本文實例講述了Android編程實現輸入框動態自動提示功能。分享給大家供大家參考,具體如下:

關于AutoCompleteTextView的使用,我想大家并不陌生,對其設定上Adapter后系統便能自己識別與匹配了。近期 一個項目中,需要做到匹配通迅錄中的電話號碼和聯系人,由于通迅錄中數據量大,所以把所有的數據在自己提示之前就查詢出來并加入到 AutoCompleteTextView中是不現實的,所以我們可以使用cursor來動態加載AutoCompleteTextView的數據,從而 實現時時搜索提示,要實現動態加載,只用重寫一個類繼承于CursorAdapter,然后設定在AutoCompleteTextView上就行了。

Android,輸入框,動態,自動提示

AutoCompleteTextView editNumber = (AutoCompleteTextView)findViewById(R.id.edit_number);Cursor cursor = getContentResolver()(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);ContactListAdapter listAdapter = new ContactListAdapter(this, cursor);editNumber.setAdapter(listAdapter);

ContactListAdapter.java中的核心代碼如下:

重寫newView方法

public View newView(Context context, Cursor cursor, ViewGroup parent) {  final LayoutInflater inflater = LayoutInflater.from(context);  final View view = (View)inflater.inflate(  R.layout.auto_complete, parent, false);  TextView txtName = (TextView)view.findViewById(R.id.txt_name);  txtName.setText(cursor.getString(0));  TextView txtNumber = (TextView)view.findViewById(R.id.txt_number);  txtNumber.setText(cursor.getString(1));  TextView txtType = (TextView)view.findViewById(R.id.txt_type);  String[] arrType = SmsConstant.ARR_CONTACTS_TYPE;  if(cursor.getint(2) > 3)  {    txtType.setText(arrType[0]);  } else  {    txtType.setText(arrType[cursor.getint(2)]);  }  return view;}

重寫bindView方法,

public void bindView(View view, Context context, Cursor cursor) {  TextView txtName = (TextView)view.findViewById(R.id.txt_name);  txtName.setText(cursor.getString(0));  TextView txtNumber = (TextView)view.findViewById(R.id.txt_number);  txtNumber.setText(cursor.getString(1));  TextView txtType = (TextView)view.findViewById(R.id.txt_type);  String[] arrType = SmsConstant.ARR_CONTACTS_TYPE;  if(cursor.getint(2) > 3)  {    txtType.setText(arrType[0]);  } else {    txtType.setText(arrType[cursor.getint(2)]);  }}

點擊彈出的Listview列表后的返回值:

public String convertToString(Cursor cursor) {}

執行搜索的sql語句,返回一個Cursor加載到彈出的Listview上

public Cursor runQueryOnBackgroundThread(CharSequence constraint) {}

在此所返回的Cursor結果,會全部顯示在彈出提示上,無需再次過慮。

希望本文所述對大家Android程序設計有所幫助。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 遂宁市| 财经| 永康市| 普兰店市| 磐石市| 台北县| 东兰县| 偃师市| 胶州市| 钦州市| 宁津县| 甘德县| 金沙县| 新蔡县| 柘荣县| 临武县| 光山县| 琼中| 莱阳市| 蒲城县| 巢湖市| 尼勒克县| 霍林郭勒市| 连州市| 曲沃县| 宁化县| 浦城县| 怀仁县| 敦化市| 镇安县| 拉萨市| 天峻县| 莲花县| 万山特区| 张掖市| 民权县| 永年县| 宿松县| 南召县| 常山县| 西藏|