|
目录结构
第一步
auto_complete_text.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<AutoCompleteTextView
android:id="@+id/myAutoCompleteTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
复制代码
第二步
MainActivity.java
package com.taofu5;
import com.taofu5.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends Activity {
private static final String[] myStr = {"aaa","bbb","ccc","aabb","aad"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.auto_complete_text);
ArrayAdapter<String> aa =
new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,myStr) {
};
AutoCompleteTextView textView =
(AutoCompleteTextView) findViewById(R.id.myAutoCompleteTextView);
textView.setAdapter(aa);
textView.setThreshold(1);
}
}
复制代码
第三步
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.taofu5"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
复制代码
效果图如下:
That's all. |
|