Android Basics Getting Started tutorial--2.4.4 ListView Focus Issue

Source: Internet
Author: User

Android Basics Getting Started tutorial--2.4.4 ListView Focus Issue

tags (space delimited): Android Basics Getting Started Tutorial

Introduction to this section:

If you add controls such as Button,checkbox,edittext to the ListView item, you may want to consider
To a problem: a focus problem in the ListView! In this section we will learn a few ways to solve this problem!
We can write a simple listview with a button,checkbox,edittext on it, but when we click Find,
The listview item cannot be clicked, cannot trigger the method of Onitemclick, also can not trigger Onitemlongclick method,
This is a focus of the ListView problem! Is the focus of the ListView being robbed by other controls, let's see how
Solve this problem?

Method 1: Set the component to preempt the control: android:focusable= "false"

Title, you can fix this by simply setting android:focusable= "false" for the control that preempted the ListView item focus
Or call after you get the control in your code:setfocusable (False)
!! In addition, EditText not, if we set the android:focusable= "false", this B can get the focus but all of a sudden
Also lost focus, and will not pop the keypad, and do not know how to solve, listen to others said to be a bug in the ListView, if
Have to know how to solve the Welcome to inform, thank you ~

Method 2:item root node settings android:descendantfocusability= "Blocksdescendants"

Title, add the above attribute on the root node of the item layout,android:descendantfocusability= "Blocksdescendants"
, and the property has three values to choose from:

  • beforedescendants: ViewGroup takes precedence over its subclass control and gets to focus
  • afterdescendants: ViewGroup gets focus only if its subclass control does not need to get focus
  • blocksdescendants: ViewGroup overrides the subclass control and gets the focus directly
This section summarizes:

OK, the above is the two ways to solve the problem of the ListView focus, very simple, if there is about EditText
Focus on the solution of the welcome proposed, thank you ~

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Basics Getting Started tutorial--2.4.4 ListView Focus Issue

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.