問題描述
我有一個 7x6 網格的 EditText
視圖.我希望在應用程序啟動時將它們全部禁用,即它們的行為應該像普通的 TextViews
并且不可編輯.然后用戶點擊網格中的一個單元格,它會更改其背景并執行一些視覺操作.如果用戶再次單擊單元格,它應該允許編輯.我正在努力使用 OnClick()
和 OnFocusChange()
監聽器,但我無法完成這樣的基本交互.
I have a 7x6 grid of EditText
views. I want all of them disabled when the application starts, ie they should behave like normal TextViews
and not to be editable. Then the user taps one cell in the grid, it changes its background and performs something visual. If the user clicks on the cell one more time it should allow editing. I'm struggling with OnClick()
and OnFocusChange()
listeners, but I can't accomplish such a basic interaction.
使用 setEnabled()
和 setFocusable()
沒有幫助.我想知道為什么即使像這樣簡單的任務在 Android 上也變得如此困難
Playing with setEnabled()
and setFocusable()
doesn't help. I wonder why even a simple task like this has been made so difficult on Android
推薦答案
我終于找到了解決方案.這是一個調用的問題
I finally found a solution. It's a matter of calling
setFocusableInTouchMode(boolean)
setFocusable(boolean)
當 EditText
第一次創建時,它可以攔截點擊.然后可以再次設置這些標志以使 EditText
可編輯,請求焦點,并使用 InputMethodManager
方法手動顯示/隱藏軟鍵盤
when the EditText
is first created, so it can intercept the clicks. Then one can set those flags back again to make the EditText
editable, request the focus, and manually show/hide the soft keyboard with InputMethodManager
methods
這篇關于EditText:如何啟用/禁用輸入?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!