简体   繁体   中英

Custom ListView Items are not clickable

I am working on an application which contains Custom ListView on its main activity. It was working fine but the day before yesterday, list view items are suddenly become non-clickable. I've searched a lot, but no answer solved my this issue. It is strange. Normal list view is working good, but custom isn't. What may be the problem?

Edit: Custom List View is as normal as it is, nothing odd. I am giving here CustomAdapter class.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null){
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.custom_list, null);
    }
    ClassDetailPedia detailPedia = personDetail.get(position);

    if(detailPedia !=null){
        TextView txtPersonName = (TextView) convertView.findViewById(R.id.txtPersonName);
        TextView txtReason = (TextView) convertView.findViewById(R.id.txtReason);
        TextView txtTags = (TextView) convertView.findViewById(R.id.txtTags);
        TextView txtDate = (TextView) convertView.findViewById(R.id.txtDate);
        ImageView imgPerson = (ImageView) convertView.findViewById(R.id.imgPerson);


        txtPersonName.setText(detailPedia.getTitle());
        txtReason.setText("Description: " + detailPedia.getDescription());
        txtTags.setText("Tags: " + detailPedia.getTags());
        txtDate.setText(GetFormattedDate(detailPedia.getDated()));

        if(detailPedia.getImage() != null) {
            imgPerson.setImageURI(detailPedia.getImage());
            imgPerson.setScaleType(ImageView.ScaleType.CENTER);
        }
    }
    return convertView;
}

and it extends ArrayAdapter<ClassDetailPedia> And here I am setting CustomAdapter

ListView lstPersons = (ListView) findViewById(R.id.lstDetail);
lstPersons.setAdapter(new CustomAdapter(getApplicationContext(), R.layout.custom_list, pediaList));

custom_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_list"
android:gravity="center">
<ImageButton
    android:layout_width="80dp"
    android:layout_height="60dp"
    android:src="@drawable/empty_picture"
    android:id="@+id/imgPerson"
    android:scaleType="centerCrop" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginTop="2dp">

    <TextView
        android:textColor="#000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Friday, April 1, 2016 @ 8:30pm"
        android:id="@+id/txtDate"
        android:textStyle="italic"
        android:textSize="12sp"
        android:layout_below="@+id/txtTags"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="3dp"
        android:layout_marginRight="3dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="Mr. Bill Gates"
        android:id="@+id/txtPersonName"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_marginStart="3dp"
        android:singleLine="true"
        android:textSize="17sp"
        android:layout_marginBottom="3dp"
        android:textStyle="bold"/>

    <TextView
        android:textColor="#000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Reason: Marketing Strategy"
        android:id="@+id/txtReason"
        android:layout_below="@+id/txtPersonName"
        android:layout_alignParentStart="true"
        android:layout_marginStart="3dp"
        android:singleLine="true"
        android:layout_marginTop="-3dp"
        android:textSize="13sp"/>

    <TextView
        android:textColor="#000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="tags: business, start-up"
        android:id="@+id/txtTags"
        android:layout_below="@+id/txtReason"
        android:layout_alignParentStart="true"
        android:layout_marginStart="3dp"
        android:singleLine="true"
        android:textSize="13sp"/>
</RelativeLayout>
</LinearLayout>

Try add android:descendantFocusability="blocksDescendants" for the root view of your custom list item (in your case it is LinearLayout )

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_list"
android:gravity="center"
android:descendantFocusability="blocksDescendants"
>
...
</LinearLayout>

I made new Application, copied and pasted all the files and code and it's working fine. I don't know what caused the problem and why it is working perfectly know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM