Fahad Saleem
Fahad Saleem

Reputation: 423

EditText field not taking input

I have an EditText field in an xml layout and I am setting that xml as the layout of a dialog box. When I click on the EditText field, it shows no response. The keyboard does not show up and cursor does not show. Here is the dialog_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="ADD"
    android:id="@+id/buttonDialog"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/editText"
    android:layout_above="@+id/buttonDialog"
    android:layout_centerHorizontal="true">
    <requestFocus />

</EditText>




</RelativeLayout>

And here is the java code:

AddBody.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v){
            final Dialog dialog = new Dialog(getApplicationContext());
            dialog.setContentView(R.layout.dialog_layout);

            dialog.show();

/*rest of the code*/

Upvotes: 1

Views: 368

Answers (1)

user1506104
user1506104

Reputation: 7106

i usually use AlertDialog to achieve the same effect.

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dialog_layout, null))
       .setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int id) {
           }
       })
       .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
           }
       });
Dialog dialog = builder.create();
dialog.show();

Using AlertDialog is recommended vs using Dialog in building your dialog layout.

Upvotes: 1

Related Questions