19

I can't seem to get this work. I already set popWindow focusable as to what I read on other forums but still no luck.

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:background="@drawable/popbg"
android:orientation="vertical" >

<Button
    android:id="@+id/cancel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:layout_marginRight="10dp"
    android:layout_marginTop="30dp"
    android:background="@drawable/zcancel" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="10dp"
    android:text="SSID"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/editText3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName" />

java

 case(R.id.settings):
 switch (event.getAction()) 
 {
case MotionEvent.ACTION_DOWN:
v.setBackgroundResource(R.drawable.cpanel2);
return true;
case MotionEvent.ACTION_UP:
v.setBackgroundResource(R.drawable.cpanel1);

LayoutInflater layoutInflater =  
    (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  

View popSwitchView = layoutInflater.inflate(R.layout.settings_xml, null);

final PopupWindow popWindow = new PopupWindow(popSwitchView);
popWindow.setWidth(LayoutParams.MATCH_PARENT);
popWindow.setHeight(LayoutParams.MATCH_PARENT);
popWindow.showAtLocation(popSwitchView, Gravity.CENTER, 0, 0);
popWindow.setOutsideTouchable(false);  
popWindow.setFocusable(true);
Drawable d = getResources().getDrawable(R.drawable.popbg); 
popWindow.setBackgroundDrawable(d);

Button CancelButton = (Button)popSwitchView.findViewById(R.id.cancel);

CancelButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
popWindow.dismiss();
}
});

                    popWindow.showAsDropDown(v, 50, -30);

                    return true;
                default:
                    return false;


            }

I'm planning on creating a popwindow of setting for network configurations. I can't seem to fix my code for a good view for you guys .

yhunz_19
  • 1,206
  • 2
  • 12
  • 17
  • Try [this](http://v4all123.blogspot.in/2013/09/custom-dialogfragmnet-example-in-android.html) and [this](http://v4all123.blogspot.in/2013/06/return-values-from-custom-popup-window.html). – Gunaseelan Feb 15 '14 at 06:14
  • can't it be done with a popupwindow? do I need to use dialog fragments. ,and I put everything there is in the second one, I really don't understand why still nothing.not working. – yhunz_19 Feb 15 '14 at 11:15

5 Answers5

60

ha, .found the answer., just did

popWindow.setFocusable(true);
popWindow.update();

thanks for the support! credits from this topic Keyboard not shown when i click on edittextview in android?

Community
  • 1
  • 1
yhunz_19
  • 1,206
  • 2
  • 12
  • 17
5

This worked for me:

popWindow.setFocusable(true);
popWindow.update();
David
  • 3,392
  • 3
  • 36
  • 47
1

Try adding this line before you show the popup:

popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Karakuri
  • 38,365
  • 12
  • 84
  • 104
1

Nothing helped me, it still didn't appear on some devices, so I had to force showing it like that (kotlin):

val editText = customView.findViewById<EditText>(numberFieldId)
        editText.onClick {
            showKeyboard(editText, context)
        }

private fun showKeyboard(mEtSearch: EditText, context: Context) {
        mEtSearch.requestFocus()
        val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
    }
Evgenia
  • 63
  • 9
-1

Try this::

Programatically:

edittext.requestFocus();

Through xml:

<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName">
    <requestFocus />
</EditText>

Hope it Helps!!

Armaan Stranger
  • 3,140
  • 1
  • 14
  • 24