我在本佈局:ListView項不接受點擊
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewText"
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="false"
android:layout_weight="1" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonOk"
android:clickable="true"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
的佈局在ListFragment使用。我也有以下代碼:
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
MyItem item = items.get(position);
//Do something...
}
我有一個自定義適配器和一個視圖。但是listview項目不可點擊。目前,我仍然沒有任何按鈕本身的代碼。我希望能夠點擊整個列表視圖項目。
是不是上述正確的方法來做到這一點?
點擊事件最簡單的方式是否使用了自定義適配器? –
@Lady_ari是的。與一個ViewHolder –
我會建議試圖設置一個'onClickListener'對父親RelativeLayout' –