Can't enter text for Edittext view inside Popupwindow?
I want to enter text from a soft keyboard into an Edittext widget inside a popup, but I am struggling with some problems. My activity is a game card table and includes some animations. The gamble has several buttons. If the player clicks on a specific button, a popup will appear. The problem is that the player cannot enter text into the Edittext inside the popup. I found some similar problems about this, and the most popular suggestion is:
Popupwindow.setFocusable(true)
With this setting, I can enter the Edittext normally. However, this blocks the main UI thread and causes the animation to stop on the games table. I don't want this to happen because it is bad for users. It is possible to show the soft keyboard when the edittext has focus using below code snippet. However, I cannot enter anything from the keyboard to the edittext. Moreover, when I close the popupwindow, the keyboard is still displayed and not closed.
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
InputMethodManager imm = (InputMethodManager)ct.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
}
}
});
Please help me find a way to enter data into Edittext without blocking animation on mainUI thread. An alternative way is to use a custom dialog, but that won't help. Using the dialog also blocks the mainUI thread. Thank you so much for any suggestion.
source to share
If you don't want to block the UI, try running this part of your code under a thread. AsyncTask would be a good choice.
Check how to use AsyncTask here: → http://developer.android.com/reference/android/os/AsyncTask.html
Luck
source to share