大家好 我也是刚开始学习Android时间不久,但是原来一直是java开发,所有Android现在学习起来比较简单,最近有一些想法就是写自己的博客,和志同道合的朋友一起成长一起学习,大家监督我能坚持多久,其实我有这个想法的已经很久了 但是一直没有坚持下来,希望以后无论多忙都能坚持写点自己的东西吧, 如果是自己敲些的demo就直接上代码了但是仅仅是关键代码,


xml代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="AutoCompleteTextView" />

<AutoCompleteTextView
android:id="@+id/autotext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</AutoCompleteTextView>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="MultiAutoCompleteTextView" >
</TextView>

<MultiAutoCompleteTextView
android:id="@+id/mul"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</MultiAutoCompleteTextView>

</LinearLayout>


java代码

package com.example.demo.baseui;

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

import com.example.demo.R;

public class MyAutoCompleteEditText extends Activity {
private AutoCompleteTextView auto;
private MultiAutoCompleteTextView mul;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bui_edittext_auto);
auto = (AutoCompleteTextView) this.findViewById(R.id.autotext);
String[] autoStrings = new String[] { "联合国", "联合国安理会", "联合国五个常任理事国",
"Google", "Google Map" };
// 第二个参数表示适配器的下拉风格
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MyAutoCompleteEditText.this,
android.R.layout.simple_dropdown_item_1line, autoStrings);
auto.setAdapter(adapter);

mul = (MultiAutoCompleteTextView) this.findViewById(R.id.mul);
mul.setAdapter(adapter);
mul.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());// 完成对选项的拆分的功能,以逗号进行拆分

}
}