(Android Control) set button implementation in ListView Item

Source: Internet
Author: User
Document directory
  • Preface
  • Cause
Preface

During project development, the Listview Item must contain the button effect. After being developed in practice, after the button is placed in the Item, the effect of changing background color in the single row of ListView is no longer displayed.

 

Cause

The reason why ListView and other widgets that can trigger the click event cannot work together is that after adding other widgets, The itemclick event of ListView cannot be triggered and is blocked by the click events of other widgets.

 

Common solutions on the Internet

Set 1 set the root layout attribute in the xml template of Item

Android: descendantFocusability = "blocksDescendants"

 

As follows:

<RelativeLayout>

Android: descendantFocusability = "blocksDescendants"

 

Set 2. Set Properties in the <ImageButton> button control.

 

Android: focusable = "false"

Supplement: After this setting, click the button and the entire Item responds to the click effect. The displayed effect is not what we need.

 

What we need

1. The items of ListView can be selected.

2. The buttons in Item can be clicked at will without interfering with Item

 

Implementation Process

Use the image control or text control in ListView to replace the image button and common button, and set the click event in the Adapter.

Example:

 

// Set the text in the click Text Box Based on the data item, and set the Click Event TextView txt_remember((textview1_convertview.findviewbyid(r.id.txt _ Remember); txt_Remember.setOnClickListener (new TextView. onClickListener () {public void onClick (View v) {LibListViewAdapter. this. remove (LibListViewAdapter. this. getItem (1 ));}});

 

Effect:

 

 

Appendix:

Android Market of science back words-Level 4 edition: http://static.apk.hiapk.com/html/2012/07/719368.html

 


 

 

 

 

 

 

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.