编辑:
我有一个ListView
链接到BaseAdapter
我实现的自定义。我为那个的项目单击事件设置了一个侦听器ListView
。在getView()
我膨胀 XML 并根据某些条件显示/隐藏一些内部布局。
问题是只有在布局内的某些按钮被隐藏时才会处理项目单击事件。我真的很困惑,不明白会发生什么。特别是,显示的按钮不允许我单击该ListView
项目是 btnEventReopen、btnEventPoll 和 btnEventRemove。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp" >
<LinearLayout
android:id="@+id/layoutEventBasic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/content_background"
android:orientation="vertical"
android:padding="8dp" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/layout_event_final_proposal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageEventPicture"
android:layout_width="92dp"
android:layout_height="92dp"
android:layout_gravity="center"
android:src="@drawable/img_event_default"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/textEventType"
style="@style/TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textEventName"
style="@style/TextView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="2"
android:textSize="16sp"
tools:ignore="NestedWeights" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layoutEventDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textEventDescription"
style="@style/TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:visibility="gone" />
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/layout_contacts" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btnEventReopen"
style="@style/ButtonPositive"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableRight="@drawable/img_reopen_icon"
android:paddingRight="0dp"
android:text="@string/reopen"
android:visibility="gone"
tools:ignore="ContentDescription" />
<Button
android:id="@+id/btnEventPoll"
style="@style/ButtonPositive"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:drawableRight="@drawable/img_accept_icon"
android:paddingRight="0dp"
android:text="@string/poll"
tools:ignore="ContentDescription" />
<Button
android:id="@+id/btnEventRemove"
style="@style/ButtonNegative"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:drawableRight="@drawable/img_reject_icon"
android:paddingRight="0dp"
android:text="@string/reject"
tools:ignore="ContentDescription" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/btnEventShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/layoutEventBasic"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:src="@drawable/img_share"
tools:ignore="ContentDescription" />
</RelativeLayout>
更多代码...
// Set the listener for handling list item click events
listEvents.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
eventExpand(position);
}
});