Android development and implementation of fragment monitoring return key event function

This paper describes the method of fragment monitoring return key events developed by Android. Share with you for your reference, as follows:

The previous article describes the basic concept and usage of fragment in detail in the definition, creation and use of fragment in Android development tutorial. Here we will analyze the specific application of fragment monitoring return key events.

background

The project requires the user to enter the page of modifying personal data after successful registration, and it is not allowed to return to the previous page. After data modification, end the current page and enter the app home page.

Since multiple fragments are used to complete the registration process, it is necessary for fragment monitoring users to click the return button on the mobile phone, check some data, and add the problems found during their use. I hereby make a record to help more friends with this need

code implementation

The above code is a solution found in stackoverflow.com, but when using it, because there may be other views (such as EditText) that can obtain focus in the fragment page, the listening will fail. Click the return key to return to the previous page.

Better solution:

In addition to the above code, we need to process the setonkeylistener of the view that can obtain the focus. Here, take an EditText as an example:

More readers interested in Android related content can view the topics on this site: summary of Android basic component usage, introduction and advanced tutorial of Android development, summary of Android layout skills, summary of Android view skills, summary of activity operation skills of Android programming, summary of Android resource operation skills, and Android control usage 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
分享
二维码
< <上一篇
下一篇>>