标签:
package com.dream.dream; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.MultiAutoCompleteTextView; import android.widget.Toast; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { private MultiAutoCompleteTextView nametext; private String[] res = { "beibi","baby","beijing","beiping","beihai", "beihaidao","beipei","babala" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); nametext = (MultiAutoCompleteTextView)findViewById(R.id.name_text); ArrayAdapter <String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,res); nametext.setAdapter(adapter); nametext.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingTop="90dp" android:paddingLeft="16dp" android:paddingRight="16dp" tools:context="com.dream.dream.MainActivity" tools:showIn="@layout/activity_main"> <MultiAutoCompleteTextView android:completionThreshold="2" android:id="@+id/name_text" android:hint="@string/name_text" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
邮件类自动补全MultiAutoCompleteTextView
标签:
原文地址:http://www.cnblogs.com/sansansan/p/5152682.html