android自动提示功能——autoCompleteTextview(二)

android自动提示功能——autoCompleteTextview(二)

自动提示的数组还可以在strings.xml文件中定义:
<resources>
    <string name="app_name">AndroidViews</string>

    <string name="title_activity_fullscreen">FullscreenActivity</string>
    <string name="dummy_button">Dummy Button</string>
    <string name="dummy_content">DUMMY\nCONTENT</string>
    <string-array name="countries_array">
        <item>aaaaaaa</item>
        <item>aaaaaa</item>
        <item>aaaaa</item>
        <item>aaaa</item>
        <item>aaa</item>
        <item>aa</item>
        <item>a1</item>
    </string-array>
</resources>

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainRelativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="xueyou.xueyoucto.com.androidviews.MainActivity">


    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="选择城市:"
        android:textSize="30sp"
        android:layout_marginTop="39dp"
        android:layout_gravity="center"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/autoCompleteTextView"
        android:layout_marginTop="25dp"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true" />


</RelativeLayout>

package xueyou.xueyoucto.com.androidviews;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private final String Tag = "MAINACTIVITY";
    private AutoCompleteTextView textView;

    private ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = (AutoCompleteTextView) this.findViewById(R.id.autoCompleteTextView);
        String[] countries = getResources().getStringArray(R.array.countries_array);
        adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,countries);
        textView.setAdapter(adapter);
    }
}

运行结果:

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wild46cat/article/details/52373632
个人分类: Android
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

android自动提示功能——autoCompleteTextview(二)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭