Android ListView in EditView again focus gets

Source: Internet
Author: User

Problem: Use EditView in the ListView to eject the keypad when the focus is given to EditView for the first time. Make EditView lose focus.

Analysis: Because the first time you use EditView to eject the keypad, the GetView method is called again. Make EditView lose focus. When you click EditView for the second time, the keypad already exists so that the GetView method is not called and therefore does not lose focus.

Idea: When you click EditView, record the position of the currently clicked view while recording the EditView cursor offset position. This record is processed at the same time as the next call to GetView.

Define two marker bits

Private int selectindex =-1; // the location of the current item Private int currentselection = 0; // Offset Amount

Then add an event with EditView focus change in GetView to record the marker bit

AdHolder.edtPrice.setOnFocusChangeListener (new  Onfocuschangelistener () {            @Override      Public void Boolean arg1) {            if(arg1==false) {            = position;             = ((EditText) view). Getselectionstart ();            " Item Location: "+position +", focus Position: "+currentselection);}}    );

Use this marker bit when redrawing the view

if (Position = = Selectindex) {    adHolder.edtPrice.requestFocus ();            AdHolder.edtPrice.setSelection (currentselection);}

Android ListView in EditView again focus gets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.