Easy Tutorial
❮ Android Tutorial Fragment Demo2 Java Math Floor Ceil Rint Round ❯

2.4.7 ListView Focus Issues

Category Android Basic Tutorial

Introduction

>

If you add Button, CheckBox, EditText, or other controls to ListView items, you might need to consider a focus issue with ListView! In this section, we will learn several methods to solve this problem.

We can create a simple ListView with a Button, CheckBox, and EditText. However, when we click, we find that the ListView item cannot be clicked, and the onItemClick and onItemLongClick methods are not triggered. This is a focus issue with ListView! The focus of ListView is being grabbed by other controls. Let's see how to solve this problem.


Method 1: Set android:focusable="false" for the control that grabs focus

>

As the title suggests, simply set android:focusable="false" for the control that grabs the focus of ListView items to solve this problem. Alternatively, you can call setFocusable(false) in the code after obtaining the control. However, EditText does not work; if we set android:focusable="false", it can get focus but immediately loses it, and the soft keyboard does not pop up. It is currently unknown how to solve this issue, and some say it is a bug in ListView. If you know how to solve it, please let us know, thank you~


Method 2: Set android:descendantFocusability="blocksDescendants" on the root node of the item

>

As the title suggests, add the attribute android:descendantFocusability="blocksDescendants" to the root node of the item layout. Additionally, this attribute has three possible values:


Summary:

>

That's all for the two methods to solve the ListView focus issue. They are very simple. If you have solutions for the EditText focus issue, please feel free to share, thank you~

-1.0 Android Basic Tutorial

-1.0.1 2015 Latest Android Basic Tutorial Contents

-1.1 Background and System Architecture Analysis

-1.2 Development Environment Setup

-1.2.1 Developing Android Apps with Eclipse + ADT + SDK

-1.2.2 Developing Android Apps with Android Studio

-1.3 Solving SDK Update Issues

-1.4 Genymotion Emulator Installation

-1.5.1 Git Tutorial: Basic Operations on Local Repository

-1.5.2 Git: Setting Up a Remote Repository on GitHub

-1.6 How to Use 9-Patch Images

-1.7 Interface Prototype Design

-1.8 Project Source Analysis (Various Files, Resource Access)

-1.9 Signing and Packaging Android Applications

-1.11 Decompiling APK to Obtain Code & Resources

-2.1 Concepts of View and ViewGroup

-2.2.1 LinearLayout (Linear Layout)

-2.2.2 RelativeLayout (Relative Layout)

-2.2.3 TableLayout (Table Layout)

-2.2.4 FrameLayout (Frame Layout)

-2.2.5 GridLayout (Grid Layout)

-2.2.6 AbsoluteLayout (Absolute Layout)

-2.3.1 Detailed Explanation of TextView (Text Field)

-2.3.2 Detailed Explanation of EditText (Input Field)

-2.3.3 Button and ImageButton

-2.3.4 ImageView (Image View)

-2.3.5 RadioButton (Radio Button) & Checkbox (Check Box)

-2.3.6 ToggleButton and Switch

-2.3.7 ProgressBar (Progress Bar)

-2.3.8 SeekBar (Drag Bar)

-2.3.9 RatingBar (Star Rating Bar)

-2.4.1 ScrollView (Scroll Bar)

-2.4.2 Date & Time Components (Part 1)

-2.4.3 Date & Time Components (Part 2)

-2.4.4 Basic Explanation of Adapter

-2.4.5 Simple Usage of ListView

-2.4.6 Optimization of BaseAdapter

-2.4.8 Solving ListView Checkbox Misalignment Issue

-2.4.9 ListView Data Update Issue

-2.5.0 Building a Reusable Custom BaseAdapter

-2.5.1 Implementing Multiple Item Layouts in ListView

-2.5.2 Basic Usage of GridView (Grid View)

-2.5.3 Basic Usage of Spinner (List Option Box)

-2.5.4 Basic Usage of AutoCompleteTextView (Auto-Complete Text Field)

-2.5.5 Basic Usage of ExpandableListView (Collapsible List)

-2.5.6 Basic Usage of ViewFlipper (Flip View)

-2.5.7 Basic Usage of Toast

-2.5.8 Detailed Explanation of Notification (Status Bar Notification)

-2.5.9 Detailed Explanation of AlertDialog (Dialog Box)

-2.6.0 Basic Usage of Other Common Dialogs

-2.6.1 Basic Usage of PopupWindow (Floating Box)

-2.6.2 Menu (Menu)

-2.6.3 Simple Usage of ViewPager

-2.6.4 Simple Usage of DrawerLayout (Official Side Menu)

-3.1.1 Event Handling Mechanism Based on Listeners

-3.2 Event Handling Mechanism Based on Callbacks

-3.3 Analysis of Handler Message Passing Mechanism

-3.4 TouchListener vs OnTouchEvent + Multi-Touch

-3.5 Listening for Content Changes in EditText

-3.6 Responding to System Settings Events (Configuration Class)

-3.7 AsyncTask Asynchronous Task

-3.8 Gestures (Gestures)

WeChat Subscription

❮ Android Tutorial Fragment Demo2 Java Math Floor Ceil Rint Round ❯