在listview中爲項目使用自定義佈局時,事實證明OnItemClickListener不會觸發。ListView的自定義佈局BreakItemClickListener
此前,我使用的是android.R.layout.two_line_list_item。我所做的只是將這個棄用的佈局換成我自己的自定義佈局。
我曾嘗試:
-setting選擇模式爲單
-enabling多空可點擊父列表和列表項
-enabling對焦和後代可聚焦
- 請求重點
任何反饋將不勝感激!
謝謝!
在listview中爲項目使用自定義佈局時,事實證明OnItemClickListener不會觸發。ListView的自定義佈局BreakItemClickListener
此前,我使用的是android.R.layout.two_line_list_item。我所做的只是將這個棄用的佈局換成我自己的自定義佈局。
我曾嘗試:
-setting選擇模式爲單
-enabling多空可點擊父列表和列表項
-enabling對焦和後代可聚焦
- 請求重點
任何反饋將不勝感激!
謝謝!
我猜你可以嘗試在customlayout的xml文件中設置android:clickable =「true」。但是你的佈局文件的代碼可能會更有幫助。
感謝您的迴應。事實證明,我能夠**部分**修復這個問題。我能夠通過在我的自定義佈局內的視圖和視圖上將focusable設置爲false來執行此操作:'android:focusable =「false」','android:focusableInTouchMode =「false」'。這個解決方案在這裏部分**工作,因爲我有一些文本視圖抓取整個**焦點(或可點擊區域)在列表項上。目前,我正在使用的文字視圖只會將潛在列表項目的可點擊區域的**部分**拿走。 – Coffee123
林不知道現在但我會嘗試從RelativeLayout屬性中刪除android:focusable =「false」&android:focusableInTouchMode =「false」,並只保留在TextView屬性中。這只是在黑暗中拍攝而已;) –
事實證明,問題實際上是一個不同的屬性**! !**該屬性是:android:textIsSelectable,如果設置爲true,它將竊取可點擊區域(非常有意義)... – Coffee123
這裏是自定義佈局...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false" >
<TextView
android:id="@+id/itemSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:textIsSelectable="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/itemSummary"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="vertical" >
<TextView
android:id="@+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="true" />
<TextView
android:id="@+id/subItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/item"
android:focusable="false"
android:focusableInTouchMode="false"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="true" />
</RelativeLayout>
</RelativeLayout>
下面是一些視圖項創建代碼...
adapter = new ArrayAdapter<ComplexObject>(this, R.layout.item_row, 0,
al) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_row, parent,
false);
}
ComplexObject item = adapter.getItem(position);
((TextView) convertView.findViewById(R.id.item)).setText(item
.getShape());
((TextView) convertView.findViewById(R.id.subItem))
.setText(item.getWeight() + " lbs");
((TextView) convertView.findViewById(R.id.itemSummary))
.setText(item.getAge() + " years");
return convertView;
}
};
您可以發佈您的自定義佈局的XML? – Catherine
凱瑟琳,我無法獲得代碼到這個網站上。這是太多的代碼... – Coffee123