gpt4 book ai didi

带有下拉列表的android edittext

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:32:39 26 4
gpt4 key购买 nike

我有一个从用户那里获取值的编辑文本。我想添加一个选项,允许用户在单击编辑文本时通过下拉列表从不同的选项中进行选择。有谁知道如何做到这一点?

这是编辑文本代码:

<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" />

我希望它看起来像这样:

enter image description here

最佳答案

我认为这是你的要求:

只要按照这个例子: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>

Activity :-

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

演示:-

enter image description here

关于带有下拉列表的android edittext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31052436/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com