简体   繁体   中英

Soft keyboard auto show when use AsyncTask

I don't know why when I use AsyncTask to load data to an Adapter, after AsyncTask finishes, the soft keyboard shows on screen.

There is a Edittext in the activity. If I delete the EditText on the Activity, after the AsyncTask finishes, the soft keyboard does not show.

I use this code on onPostExecute() but it does not work:

protected void onPostExecute(String[] result) {
        hideSoftKeyboard(SearchActivity.this);
        RecommendAdapter mAdap = new RecommendAdapter(con, mLocation);
        mListview.setAdapter(mAdap);

        if (dialog.isShowing()) {

            dialog.dismiss();
        }

    }
public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}

现在我知道了答案。这是因为我使用它,所以它始终专注于。将android:focusable="true" android:focusableInTouchMode="true"到布局中,以便不显示软键盘。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM