码迷,mamicode.com
首页 > 其他好文 > 详细

邮件类自动补全MultiAutoCompleteTextView

时间:2016-01-23 01:34:10      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!