Android:UI控件AutoCompleteTextView、MultiAutoCompleteTextView、include、merge、Tokenizer

  1. 云栖社区>
  2. 博客>
  3. 正文

Android:UI控件AutoCompleteTextView、MultiAutoCompleteTextView、include、merge、Tokenizer

余二五 2017-11-14 17:15:00 浏览512
展开阅读全文
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
public class MainActivity extends Activity
{
    /*
     * 1.ems 输入长度
     * 2.inputType 输入类型
     *
     * 3.completeTextView设置:
     * android:completionThreshold="1"  设置从第几个字母开始查询记录
     *
     * 4.<requestFocus />默认获得焦点
     *
     * 5.复用控件的方法:可再设置属性
     * <include layout="@layout/relayout"
     *  android:layout_width="match_parent"
     *  android:layout_height="match_parent"
     *  android:layout_below="@+id/autoCompleteTextView1" />
     *
     * 6.当根布局是framelayout时,可以使用merge复用系统的布局,合并重复的layout
     * <merge xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
       <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
     * </merge>
     */
         
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
             
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
        AutoCompleteTextView cTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
        cTextView.setAdapter(adapter);
             
        MultiAutoCompleteTextView mulcTextView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
        mulcTextView.setAdapter(adapter);
        mulcTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
             
        //tokenizer关键分隔符
        String str = "dafs,asdfa,dafdaf,dasfdsaff,trhfd,gfdhyj,hgjff";
        StringTokenizer tokenizer = new StringTokenizer(str, ",");
        while(tokenizer.hasMoreElements())
        {
           Object nextments = tokenizer.nextElement();
           System.out.println(nextments);
        }
    }
         
    static final String[] COUNTRIES = new String[] {
        "Afghanistan""Albania""Algeria""American Samoa""Andorra",
        "Angola""Anguilla""Antarctica""Antigua and Barbuda""Argentina",
        "Armenia""Aruba""Australia""Austria""Azerbaijan",
        "Bahrain""Bangladesh""Barbados""Belarus""Belgium",
        "Belize""Benin""Bermuda""Bhutan""Bolivia" };
             
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
         
}




本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1203963,如需转载请自行联系原作者

网友评论

登录后评论
0/500
评论
余二五
+ 关注