关闭

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

200人阅读 评论(0) 收藏 举报
分类:

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);
    }
}

运行结果:

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:356779次
    • 积分:7987
    • 等级:
    • 排名:第2768名
    • 原创:442篇
    • 转载:12篇
    • 译文:7篇
    • 评论:40条
    文章分类
    最新评论