[Turn]android in the ListView click event Expires

Source: Internet
Author: User

Let's start by explaining the features I want to achieve:

Click on an item to change its color. If there are many examples of changes online, I will not swim. The ListView is not responding because the Middle Green section (one of its own definitions of inherited Baseadapter adapter to fit the ListView) overwrites the ListView item. Now just click on the Convertview in the custom adapter.

Second, a custom adapter contains a ImageView and two textview. The code is as follows:

<?xml version="1.0" encoding="Utf-8"?>

<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"

Android:layout_width="Fill_parent"

android:layout_height="Wrap_content"

android:background="#fcfcfc"

android:orientation="Vertical"

android:padding="6DP"

android:descendantfocusability="blocksdescendants">

<relativelayout

Android:layout_width="Match_parent"

android:layout_height="60DP"

android:background="@drawable/mm_listitem"

android:focusable="false"

android:gravity="center_vertical" >

<imageview

android:id="@+id/userphoto"

Android:layout_width="55DP"

android:layout_height="55DP"

android:layout_alignparentleft="true"

Android:layout_centervertical="true"

android:paddingleft="5DP"

android:src="@drawable/xiaohei" />

<textview

android:id="@+id/friendname"

Android:layout_width="Wrap_content"

android:layout_height="Wrap_content"

android:layout_torightof="@id/userphoto"

android:padding="7DP"

android:textcolor="#000" />

<textview

android:id="@+id/sendtime"

Android:layout_width="Wrap_content"

android:layout_height="Wrap_content"

android:layout_alignparentright="true"

android:padding="7DP"

android:textcolor="#666" />

<textview

android:id="@+id/friendstate"

Android:layout_width="Wrap_content"

android:layout_height="Wrap_content"

android:layout_alignparentbottom="true"

android:layout_torightof="@id/userphoto"

android:padding="7DP"

android:textcolor="#666" />

</RelativeLayout>

</LinearLayout>

Workaround:

Add the LinearLayout in the XML above

Android:descendantfocusability= "Blocksdescendants"

That can be resolved.

Then click on the item that can be clicked on toast.

The custom adapter GetView did not make any changes.

[Turn]android in the ListView click event Expires

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.