1. 利用(AutoCompleteTextView)物件來達到自動填入文字
2. MainActivity.java
01.
package
org.me.android_autocompletetextview;
02.
import
android.app.Activity;
03.
import
android.os.Bundle;
04.
import
android.widget.ArrayAdapter;
05.
import
android.widget.AutoCompleteTextView;
06.
07.
public
class
MainActivity
extends
Activity {
08.
private
AutoCompleteTextView autoComplete;
09.
10.
@Override
11.
public
void
onCreate(Bundle icicle) {
12.
super
.onCreate(icicle);
13.
setContentView(R.layout.main);
14.
autoComplete = (AutoCompleteTextView) findViewById(R.id.autoComplete);
15.
String[] phone =
new
String[]{
"0986254878"
,
"0985225787"
,
"098525879"
,
"0985012486"
,
"0985658745"
};
16.
//設定自動填入的文字內容
17.
ArrayAdapter<string> adapter =
new
ArrayAdapter<string>(
this
,android.R.layout.simple_spinner_item,phone);
18.
autoComplete.setAdapter(adapter);
19.
}
20.
}
21.
</string></string>
3. main.xml(Layout)
01.
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
02.
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
03.
android:orientation
=
"vertical"
04.
android:layout_width
=
"fill_parent"
05.
android:layout_height
=
"fill_parent"
>"
06.
<
AutoCompleteTextView
07.
android:id
=
"@+id/autoComplete"
08.
android:layout_width
=
"fill_parent"
09.
android:layout_height
=
"50px"
>
10.
</
AutoCompleteTextView
>
11.
</
LinearLayout
>
全站熱搜
留言列表