0

Say "I want users to select from a dropdown list while filling a form, e.g Sex". Can I achieve exactly what is in the image attached? If yes, how?

enter image description here

Molly
  • 1,887
  • 3
  • 17
  • 34
developerTobi
  • 41
  • 1
  • 8

2 Answers2

1

You can add an arrow image as drawable-right/drawable-end. Set focusable properties and cursor visibility false and on click of Edit text open a dialog with list. For the background use same background you are using for email-address edittext. Below is Sample XML Code

            <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" />
User
  • 692
  • 2
  • 11
  • 29
0

I guess this should do:

The XML files should be:

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

And the MainActivity.java should be

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);
    }
}
Keyur Kariya
  • 69
  • 2
  • 12