AutoCompleteTextView 的用法

写一个拷贝android程式的数据库的小工具,每次都完整输入路径太麻烦,于是查资料发现android中有一个AutoCompleteTextView的控件。
在网上查找用法,发现两个不同的用法,另外还有一个可以调整下拉框格式的方法。

共同代码:

private static final String[] PATHS = new String[]{
            "/data/data/com.xxxx.home/databases",
            "/data/data/com.xxxx.bookshelf/databases",
            "/data/data/com.xxxx.ui/databases",
            "/data/data/com.xxxx.schduler/databases",};

方法一:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, PATHS);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
    textView.setAdapter(adapter);

方法二:

ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, PATHS);
    AutoCompleteTextView textView2 = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView2);
    textView2.setAdapter(adapter2);

下拉框格式调整方法:
      参考网址:http://ysl-paradise.blogspot.tw/2008/06/this-pref.html
      找到simple_list_item_1.xml档案,其格式如下:

   <?xml version="1.0" encoding="utf-8"?>  
   <TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:textAppearance="?android:attr/textAppearanceLarge"  
    android:id="@android:id/text1"  
    android:paddingTop="2dip"  
    android:paddingBottom="3dip"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content" />

    新建一个small_list_item_1.xml 檔,放在 layout 的目錄下。

     <!-- 其中android:textSize,android:textColor,android:background为自定义的属性 -->
   <TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:textAppearance="?android:attr/textAppearanceLarge"  
    android:id="@android:id/text1"  
    android:paddingTop="2dip"  
    android:paddingBottom="3dip"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:textSize="14sp"
    android:textColor="#FFFF0000"
    android:background="#FF87CEFA"/>

    程式码:

ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this,
          R.layout.small_list_item_1, PATHS);
   AutoCompleteTextView textView3 = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView3);
   textView3.setAdapter(adapter3);

另外android还有另外一个控件:MultiAutoCompleteTextView
参考网址:http://blog.csdn.net/lijiecong/article/details/4935109
具体没有测试。

posted @ 2012-07-20 14:43  日光之下无新事  阅读(491)  评论(0编辑  收藏  举报