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