Android學習筆記(3)—AutoCompleteTextView的使用

來源:互聯網
上載者:User

註:下面例子是工程:mydictionary的一些片段,其中也涵蓋了對檔案的讀寫

1、聲明

private AutoCompleteTextView mytext;

2、調用

mytext = (AutoCompleteTextView) findViewById(R.id.edit);mytext.setThreshold(1);//設定輸入一個字元就開始執行TextChangeListener change = new TextChangeListener();mytext.addTextChangedListener(change);

3、TextChangeListener監聽器

public class TextChangeListener implements TextWatcher {public void beforeTextChanged(CharSequence s, int start, int count,int after) {// TODO Auto-generated method stubSystem.out.println("--->before");}public void afterTextChanged(Editable s) {// TODO Auto-generated method stubSystem.out.println("--->after");}public void onTextChanged(CharSequence s, int start, int before,int count) {// TODO Auto-generated method stubSystem.out.println("--->on");InputWhere(s.toString());try {list = new ArrayList<String>();list.clear();RandomAccessFile in = new RandomAccessFile(FILENAME, "r");for (int k = 0; k < 30; k++) {in.seek(2048 + 54 * (mid + k - 3));char chword[] = new char[25];int i = 0;byte buffer1 = in.readByte();byte buffer2 = in.readByte();while (!((buffer1 == 0) && (buffer2 == 0))) {chword[i] = (char) ((buffer2 << 8) | (buffer1 & 0xff));buffer1 = in.readByte();buffer2 = in.readByte();i++;if ((2 + i * 2) >= 50)break;if (mid + k > 9119)break;}StringBuffer sub = new StringBuffer(); sub.append(chword);sub.setLength(i);list.add(sub.toString()); }mytext.setAdapter(new ArrayAdapter<String>(mydictionary.this,android.R.layout.simple_dropdown_item_1line, list));} catch (Exception e) {// TODO: handle exceptione.printStackTrace();}}}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.