Detailed explanation of hidden soft keyboard function in listview and EditText post of Android programming

This article describes the function of hiding the soft keyboard in listview and EditText posts of Android programming. Share with you for your reference, as follows:

In Android development, it is sometimes a very common requirement to manually call the hiding and display of the software disk.

EditText control realizes the function of clicking to open the soft keyboard input, but why? Why can EditText Click to pop up the keyboard, but textview cannot? What modifications have EditText made to inherit textview? For these problems, you have to see how to implement the relevant specific code. You can refer to the seemingly simple control. In fact, the system encapsulation and implementation is very complex. Here's a warning for developers who, like me, are good at thinking about the essence behind the event and encourage each other.

There is a layout in the development. The outermost layer is FrameLayout, which wraps the listview. At the bottom is an edit input box. When you click the input box to open the keyboard, you need to slide the listview to hide the keyboard, but slide up and continue to slide the listview.

At the beginning, I tried to set clicklistener for listview, onscrolllistener and rewrite its ontouchevent method, but I found that I was not satisfied with the effect (I found that the code has been modified for some time, and I have a sense of entanglement until I am satisfied with it).

Why not? Every time the listview slides, calling the hide keyboard will cause the listview to flash and ghosting. Because the listview is sliding, the hide keyboard is called, and the activity setting is adjustresize, which will rearrange the onlayout whole layout. (PS: I've been struggling with this problem before. The adjustresize attribute causes the edit at the bottom not to move with the keyboard, but after the keyboard is opened, the edit is in the appropriate position in the layout. Finally, the problem summarized is that the layout needs to be adjusted and the adjustpan attribute is used. I believe that the similar wechat chat interface must do the same. There are better ways. Welcome to leave a message for discussion!)

Reintroduced the onintercepttouchevent interception touch method of the outermost FrameLayout. Paste the code directly

Of course, the touch method can only be intercepted when the keyboard pops up, so it is necessary to check whether the keyboard has popped up. How to detect

Onlayoutchangelistener listens for changes in the layout of the control. View also has a listener getviewtreeobserver(). Addongloballayoutlistener (New ongloballayoutlistener()). When this listener method is called, it is called back after listening in my test.

Here, the horizontal and vertical screen switching is realized. The horizontal screen is to click the input box, first return to the vertical screen, and then pop up the keyboard. The above two listeners and onconfigurationchanged are used.

So when you debug step by step, you finally achieve your satisfaction.

EditText it's actually easier to put away the keyboard and directly rewrite ontouchevent

This parameter tells us that hidesoft will not be called for many times. Hahaha.

In fact, edit is a very high edit. Like listview, this method will cause the keyboard to be retracted during the sliding of edit, resulting in ghosting because of adjustresize and layout.

In fact, if the system can encapsulate the method, click Show keyboard, then click Hide keyboard without sliding edit, so if you want to modify the code, you must understand why edit can click Show keyboard.

More readers interested in Android related content can view the special topics of this site: Android control usage summary, Android development introduction and advanced tutorial, Android view skill summary, activity operation skill summary of Android programming, Android database operation skill summary and Android resource operation skill summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>