0
有沒有什麼方法在Android中實現自動完成單詞提示,並從數據庫中檢索單詞提示?如何在Android中實現自動完成單詞提示?
有沒有什麼方法在Android中實現自動完成單詞提示,並從數據庫中檢索單詞提示?如何在Android中實現自動完成單詞提示?
我已經做到了,請閱讀給定的打擊代碼。我希望這對你非常有用。
public static String[] COUNTRIES = { "Afganistan", "Algeria", "Albania",
"Angola", "Anguilla", "Antigua and\nBarbuda", "Argentina",
"Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
"Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus" };
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.txtCountry);
countryNames = COUNTRIES; // this is where you would fire a loader
// and set the adapter when you get a result, so the following would be in a callback
ed.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, countryNames));
}
它自動完成的TextView
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<AutoCompleteTextView android:id="@+id/myautocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
/>
</LinearLayout>
AndroidAutoCompleteTextView.java
package com.AndroidAutoCompleteTextView;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class AndroidAutoCompleteTextView extends Activity implements TextWatcher{
AutoCompleteTextView myAutoComplete;
String item[]={
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myAutoComplete = (AutoCompleteTextView)findViewById(R.id.myautocomplete);
myAutoComplete.addTextChangedListener(this);
myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, item));
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
}
太遺憾了!我無法訪問此鏈接,也許它被阻止。 – David 2011-06-14 04:13:44