机器人用的EditText下拉列表 [英] android edittext with drop down list

查看:311
本文介绍了机器人用的EditText下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从用户获得值一个EditText。我要添加一个选项,允许用户点击的EditText时通过下拉列表从不同选项中进行选择。有没有人有一个想法如何做到这一点?

I have an edittext which gets values from the user. I want to add an option which allows the user to choose from different options via drop down list when edittext is clicked. Does anyone have an idea how to do this?

这是EditText上code:

This is edittext code:

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:id="@+id/dish_quantity"
    android:layout_below="@+id/dish_name"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:hint="Quantity" />

我希望它看起来是这样的:

I want it to look like this:

推荐答案

我觉得这是你的要求:

只要按照这个例子:
XML: -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >   
<AutoCompleteTextView
    android:id="@+id/languages"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"></AutoCompleteTextView>
</LinearLayout>

活动: -

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

public class MainActivity extends Activity {

    String[] languages = { "C","C++","Java","C#","PHP","JavaScript","jQuery","AJAX","JSON" };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
                //Create Array Adapter
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.select_dialog_singlechoice, languages);
                //Find TextView control
        AutoCompleteTextView acTextView = (AutoCompleteTextView) findViewById(R.id.languages);
        //Set the number of characters the user must type before the drop down list is shown
                acTextView.setThreshold(1);
                //Set the adapter
        acTextView.setAdapter(adapter);
    }
}

演示: -

这篇关于机器人用的EditText下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆