如何在edittext中创建下拉列表?注意:我不想使用微调器[关闭]

问题描述 投票:0回答:2

说“我希望用户在填写表单时从下拉列表中选择,例如Sex”。我可以准确地获得所附图像中的内容吗?如果有,怎么样?

enter image description here

android android-edittext android-spinner
2个回答
0
投票

您可以将箭头图像添加为drawable-right / drawable-end。设置可聚焦属性和光标可见性为false,单击“编辑”文本打开带列表的对话框。对于后台使用相同的背景,您使用的是电子邮件地址edittext。以下是示例XML代码

            <EditText
            android:id="@+id/etCustomerType"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_40sdp"
            android:layout_marginStart="@dimen/_15sdp"
            android:layout_marginEnd="@dimen/_15sdp"
            android:backgroundTint="@color/editTextTextColor"
            android:cursorVisible="false"
            android:drawableEnd="@drawable/ic_dropdown"
            android:drawableRight="@drawable/ic_dropdown"
            android:drawablePadding="@dimen/_10sdp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:paddingStart="@dimen/_10sdp"
            android:paddingEnd="@dimen/_10sdp"
            android:textColor="@color/editTextTextColor"
            android:textColorHint="@color/editTextTextColor"
            android:textCursorDrawable="@color/editTextTextColor"
            android:textSize="@dimen/textSizeXSmall" />

0
投票

我想这应该做:

XML文件应该是:

<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/sex"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"></AutoCompleteTextView>
</LinearLayout>

MainActivity.java应该是

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

public class MainActivity extends Activity {

    String[] sex = { "Male", "Female" };



    @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, sex);
                //Find TextView control
        AutoCompleteTextView acTextView = (AutoCompleteTextView) findViewById(R.id.sex);
        //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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.