The ListView has Edittextview, solve the problem that EditView can't get focus after pop-up keyboard

Source: Internet
Author: User

Although the ListView inside the dynamically generated Edittextview is not the Android UI friendly, but the demand is like this, then you have to bite the bullet to do

The problem is to click EditText, the keyboard pop-up, the input cursor will disappear, need to click again to get the cursor, this is probably because the ListView does not handle the EditText as item, pop-up keyboard should view is regenerated.

Tossing the day, the solution is as follows:


Layout file (Nothing special):

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" fill_parent "    android:layout_height=" fill_parent ">    < Framelayout        android:id= "@+id/booking1_framelayout"        android:layout_width= "Fill_parent"        android: layout_height= "40DP"        android:background= "@drawable/header" >        <textview            style= "@style/title_ Text_style "            android:text=" @string/booking2 "/>    </FrameLayout>    <listview        android: Id= "@+id/book2_listview"        android:layout_width= "fill_parent"        android:layout_height= "Fill_parent"         android:layout_below= "@id/booking1_framelayout"        android:divider= "@null"        android:paddingleft= " 10DP "        android:paddingright=" 10DP "/></relativelayout>

Key code:

In the GetView method of the adapter of the ListView:

Click to record which EditText is now clicked, which is the edit EditText
ViewHolderChild.name.setOnTouchListener (New Ontouchlistener () {@Overridepublic Boolean onTouch (View V, motionevent Event) {if (event.getaction () = = motionevent.action_up) {touchedposition = position;} return false;}}); if (touchedposition = = position) {//If the current row subscript is consistent with the index saved in the Click event, manually set the focus for EditText. ViewHolderChild.name.requestFocus ();} else {viewHolderChild.name.clearFocus ();}

The main mechanism for the ListView is not yet well understood.


The ListView has Edittextview, solve the problem that EditView can't get focus after pop-up keyboard

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.