久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Android 4.x 上按下時 Listview 中的 EditText 失去焦

EditText in Listview loses focus when pressed on Android 4.x(在 Android 4.x 上按下時 Listview 中的 EditText 失去焦點)
本文介紹了在 Android 4.x 上按下時 Listview 中的 EditText 失去焦點的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我知道這里有很多類似的問題但我無法在一個簡單的示例應用程序中獲得任何提供的解決方案.

I know there are a lot of similar questions out here but I couldn't get any of the provided solutions working in a simple sample app.

第一次顯示軟鍵盤時會出現問題.一旦顯示出來,只有再次按下 editText 才能使其可編輯.

The problem occurs when the softkeyboard is shown for the first time. As soon as it is shown, only by pressing the editText again makes it editable.

嘗試了以下方法:

 android:windowSoftInputMode="adjustPan|adjustResize"

這并不能解決任何問題.在彈出軟鍵盤后,似乎必須強制調整活動的大小.不幸的是,它還會導致任何 EditTexts 失去焦點.這可能是 ListView 本身在調整大小過程后獲得焦點.所以我嘗試了以下解決方法:

This is not solving any issues. It seems that this line is mandatory to have the activity resized after the softkeyboard is popping up. Unfortunately, it's also causing any EditTexts to lose focus. This is probably to the ListView itself gaining focus after the resizing process. So I tried the following workaround:

 listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

這總是會導致 ListView 包含的第一個 可見 EditText 獲得焦點,這是不希望的.第二行中的第二個 EditText 應該在按下時獲得焦點,這沒有發生.此外,如果我最終設法將焦點集中在顯示的第一個之外的另一個 EditText(例如,通過按 softkeyboard 上的下一步"),第一個可見的將在鍵盤被關閉并且 ListView 后獲得焦點再次調整為完整大小.

This always causes the first visible EditText that the ListView contains to gain focus, which is undesirable. The second EditText in the second row should instead gain focus when pressed, which is not happening. Also, if I eventually managed to focus another EditText other then the first one shown (e.g. by pressing 'Next' on the softkeyboard), the first visible one will receive focus after the keyboard is dismissed and the ListView being resized to its full size again.

我嘗試了其他一些方法,例如攔截 ListView 的 onFocusChange() 事件,同時知道哪個 EditText 被它的 TouchListener 按下.再次請求某個 EditText 的焦點也沒有成功.

I tried several other things like intercepting onFocusChange() events for the ListView, while knowing which EditText was pressed by its TouchListener. Requesting the focus for that certain EditText again did not lead to any success either.

使用 ScrollView 而不是其他用戶建議的 ListView 也不是相關項目的選擇.

Using a ScrollView instead of a ListView as suggested by other users is not an option either for the concerned project.

推薦答案

針對這種情況的經典技巧是使用處理程序和 postDelayed().在您的適配器中:

A classic hack for situations like this is to use a handler and postDelayed(). In your adapter:

private int lastFocussedPosition = -1;
private Handler handler = new Handler();

public View getView(final int position, View convertView, ViewGroup parent) {

    // ...

    edittext.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        if (lastFocussedPosition == -1 || lastFocussedPosition == position) {
                            lastFocussedPosition = position;
                            edittext.requestFocus();
                        }
                    }
                }, 200);

            } else {
                lastFocussedPosition = -1;
            }
        }
    });

    return convertView;
}

這適用于我的設備,但不要將此代碼用于生產.如果焦點錯誤在不同的 android 版本或 rom 中表現不同,我也不會感到驚訝.

This works on my device, but keep this code out of production. I also wouldn't be surprised if the focus bug manifests itself differently in different android versions or roms.

ListView 中嵌入 EditText 還存在許多其他問題,這些問題的解決方案感覺就像是 hack.查看所有 其他 人們在苦苦掙扎.

There are also many other problems with embedding an EditText within a ListView that have solutions that feel like a hack. See all of the other people struggling.

這樣的事情也很容易發生:

It's also very easy to have something like this happen:

.

在我自己多次走類似的道路后,我大多放棄了嘗試覆蓋任何默認鍵盤行為或怪癖.如果可能,我建議您嘗試在您的應用中找到替代解決方案.

After having gone down similar paths many times myself, I've mostly given up on trying to override any of the default keyboard behaviours or quirks. I would recommend trying to find alternative solution in your app if possible.

您是否考慮過讓 ListView 行只是一個樣式化的 TextView,然后顯示一個帶有 EditTextDialog> 單擊一行時,是否根據需要更新 TextView?

Have you considered having the ListView rows be just a styled TextView and then displaying a Dialog with an EditText when a row is clicked, updating the TextView as necessary?

這篇關于在 Android 4.x 上按下時 Listview 中的 EditText 失去焦點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
主站蜘蛛池模板: 特黄毛片视频 | 91久久国产精品 | 亚洲欧美激情精品一区二区 | 人人澡人人爱 | 欧美日韩一卡二卡 | 日本精品一区二区三区四区 | 国产乱码精品一区二区三区忘忧草 | 男人的天堂中文字幕 | 性色综合 | 国产久视频| 中文字幕免费中文 | 久久精品免费一区二区三 | 亚洲人成人一区二区在线观看 | 欧美精品91 | 99久久婷婷国产综合精品电影 | 久久久久久亚洲精品 | 中文成人在线 | 午夜在线免费观看视频 | 日韩一二区 | 日本高清不卡视频 | 国产在线a | 国产高清视频在线 | 天天操天天摸天天干 | 久久久久亚洲精品中文字幕 | 操操日 | xnxx 日本免费 | 成人精品视频 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 国产大片黄色 | 国产亚洲精品久久久久久牛牛 | 久久久久国产一区二区三区 | 国产精品一区一区 | 91伊人| 日韩欧美网 | 一级毛片免费看 | 精品国产黄a∨片高清在线 成人区精品一区二区婷婷 日本一区二区视频 | 电影午夜精品一区二区三区 | 日韩av一区二区在线观看 | 亚洲日韩中文字幕一区 | 激情网站| 国产成都精品91一区二区三 |