a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 系統(tǒng) > Android > 正文

Android編程實現(xiàn)輸入框動態(tài)自動提示功能

2019-12-12 03:29:14
字體:
供稿:網(wǎng)友

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

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

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) {}

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

public Cursor runQueryOnBackgroundThread(CharSequence constraint) {}

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

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》及《Android控件用法總結(jié)

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 欧美日韩国产综合视频 | 日韩欧美精品在线视频 | 四虎5151久久欧美毛片 | 91亚洲精品视频 | 欧美日韩一区二区三区在线观看 | 精品久久久久久久久久 | 麻豆精品国产91久久久久久 | 欧美日本韩国一区二区 | 91精品久久久久 | 日韩一区二区三免费高清在线观看 | 涩婷婷| 欧美一级在线观看 | 日韩不卡一区 | 夜夜嗨av涩爱av牛牛影视 | 岛国av免费观看 | 在线成人免费视频 | 国产视频一区二区在线 | 97精品超碰一区二区三区 | 国产精品456在线影视 | 在线视频一区二区 | 国产乱码一区二区三区 | 亚洲一区二区三区国产 | 天天操夜夜干 | 国产高清毛片 | 久草在线在线精品观看 | 亚洲久久 | 亚洲男人天堂2023 | 欧美日韩在线播放 | 欧美精品一区二区三区在线四季 | 久久久91精品国产一区二区精品 | 午夜精品一区二区三区免费视频 | 国产在线不卡视频 | 亚洲巨乳自拍在线视频 | 亚洲一区二区在线免费观看 | 黄色天堂在线观看 | 日韩在线精品强乱中文字幕 | 久久久99精品免费观看 | 欧州一区二区三区 | 欧美一区 | 青草青草久热精品视频在线观看 | 午夜影院在线观看 |