Nikhil
Nikhil

Reputation: 155

Unable to click edittext inside inside linear layout, inside pop up window

I have an edit text that is inside a linear layout. And the linear layout is inside a pop window.

When I run the app, I am unable to click and enter input for the edit text.

Code for the pop up window it is inside the onCreateView of my fragment:

final Button makeoffer = (Button) view.findViewById(R.id.make_offer);
    makeoffer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LayoutInflater layoutInflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View popupView = layoutInflater.inflate(R.layout.offer_popup, null);
            final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            EditText mEditText = (EditText) popupView.findViewById(R.id.payment_field);
            popupView.clearFocus();
            mEditText.requestFocus();
            popupWindow.setFocusable(true);
            popupWindow.update();

            final Spinner spinner1 = (Spinner) popupView.findViewById(R.id.transaction_spinner);
            spinner1.setAdapter(new ArrayAdapter<CharSequence>(getActivity(), R.layout.support_simple_spinner_dropdown_item,getActivity().getResources().getTextArray(R.array.payment_list)));

            Button btnDismiss = (Button)popupView.findViewById(R.id.cancel2);
            btnDismiss.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    popupWindow.dismiss();
                }
            });
            popupWindow.showAtLocation(popupView, Gravity.NO_GRAVITY, 0, 0);
        }
    }); 

XML code of the layout for the pop up window:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_height="match_parent"
android:background="#BF000000">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:textColor="#FFFFFF"
    android:textSize="25sp"
    android:layout_marginTop="120dp"
    android:text="Make an Offer"/>

<LinearLayout
    android:layout_width="300dp"
    android:layout_height="60dp"
    android:orientation="horizontal"
    android:layout_marginLeft="40dp"
    android:layout_marginTop="20dp"
    android:layout_gravity="top|left"
    android:background="#FFFFFF"
    android:layout_marginBottom="20dp"
    android:descendantFocusability="blocksDescendants">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|left"
        android:textColor="#00ff00"
        android:paddingLeft="10dp"
        android:paddingTop="5dp"
        android:text="Your Offer: "/>



        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="#000000"
            android:textSize="18sp"
            android:paddingLeft="10dp"
            android:text="$"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="38sp"
        android:hint="Amount"
        android:id="@+id/payment_field"
        android:textColor="#000000"
        android:paddingLeft="5dp"
        android:background="#FFFFFF"
        android:layout_gravity="center_vertical"
        android:textColorHint="#000000"/>

    </LinearLayout>

<Spinner
    android:id="@+id/transaction_spinner"
    android:spinnerMode="dialog"
    android:layout_width="300dp"
    android:layout_height="50dp"
    android:popupBackground="#00688B"
    android:layout_marginBottom="15dp"
    android:layout_marginLeft="40dp"
    android:background="#FFFFFF"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:textColor="#00ff00"
    android:layout_marginLeft="100dp"
    android:textSize="15sp"
    android:paddingLeft="10dp"
    android:layout_marginBottom="15dp"
    android:text="How does this work?"/>

<Button
    android:layout_width="300dp"
    android:layout_height="40dp"
    android:layout_marginLeft="40dp"
    android:layout_marginTop="10dp"
    android:background="#228b22"
    android:text="Review Offer"
    android:inputType="textFilter"
    android:id="@+id/review_offer"
    android:textColor="#FFFFFF"
    android:layout_marginBottom="10dp"
    />
<Button
    android:layout_width="300dp"
    android:layout_height="40dp"
    android:layout_marginLeft="40dp"
    android:layout_marginTop="10dp"
    android:background="#FFFFFF"
    android:text="Cancel"
    android:inputType="textFilter"
    android:id="@+id/cancel2"
    android:textColor="#000000"
    android:layout_marginBottom="10dp"
    />

Upvotes: 1

Views: 1338

Answers (1)

Nikhil
Nikhil

Reputation: 155

For anyone else reading this:

Thanks a lot @AnkiiRawat. What I did was I got rid of android:descendantFocusability="blocksDescendants" in the xml file. And in the LinearLayout that contains the EditText I added the android:descendantFocusability="afterDescendants" attribute.

Upvotes: 2

Related Questions