Java-Android 之输入提示框

Android的文本提示框有两种方式:

main.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"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="模糊查询" />
    <AutoCompleteTextView 
        android:id="@+id/autotext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        
        />
    <MultiAutoCompleteTextView
        android:id="@+id/mull"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

</LinearLayout>

 MainActivity.java文件

package cn.szy.com;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
	private MultiAutoCompleteTextView move;
	private AutoCompleteTextView auto;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        auto = (AutoCompleteTextView)this.findViewById(R.id.autotext);
        String [] autoStrings = new String [] {
        		"联合国",
        		"联合军",
        		"联邦"
        };
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_dropdown_item_1line,autoStrings);
        auto.setAdapter(adapter) ;
        move = (MultiAutoCompleteTextView)this.findViewById(R.id.mull);
        move.setAdapter(adapter) ;
        move.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    }
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。