ListView Androidはセレクタが機能したり、選択を許可したりしません
-
14-11-2019 - |
質問
大丈夫私はこれがListViewとListactivityの問題に関する他の問題のように聞こえるかもしれないことを知っていますが、これは私がこれまでに行ったときに私が持っているので夢中になるつもりです、そしてこれに対する解決策を見つけるためにすべての投稿を検索しましたそれは私を助けるかもしれません。すでに試してみました ListView項目の背景と GetView VS.カスタムCursorAdapterのBINDVIEW?
test_list_view.xml の一部
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:cacheColorHint="#00000000"
android:focusable="true"
android:listSelector="@color/row_selector"
android:background="@color/Transparent"/>
.
SELECTOR.XMLの一部(基本的にコピーされ、上記のリンクのいずれかから貼り付け)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/Transparent" />
<item
android:state_focused="true"
android:state_enabled="false"
android:state_pressed="true"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:state_enabled="false"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@color/blue" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@color/blue" />
<item
android:state_focused="true"
android:drawable="@color/green" />
<item
android:state_selected="true"
android:drawable="@color/blue" />
<item
android:drawable="@color/Transparent" />
</selector>
.
私は私が知っておらず、依然として何もないすべてのオプションを続けた。 唯一の大きな違いはGUYS私はgetView
を使用していません。代わりにbindView
を使用しています。
任意の助けが高く評価されます。
事前にありがとうございました。
Sanj
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:cacheColorHint="#00000000"
android:focusable="true"
android:listSelector="@color/row_selector"
android:background="@color/Transparent"/>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/Transparent" />
<item
android:state_focused="true"
android:state_enabled="false"
android:state_pressed="true"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:state_enabled="false"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@color/blue" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@color/blue" />
<item
android:state_focused="true"
android:drawable="@color/green" />
<item
android:state_selected="true"
android:drawable="@color/blue" />
<item
android:drawable="@color/Transparent" />
</selector>
.
getView
を使用していません。代わりにbindView
を使用しています。
解決
I suggest that you remove the android:focusable="true"
from the ListView
.
Additionally, you can use the selector
as the background color of the items that are displayed in the ListView
. Also be sure that those elements are not calling onClick
or onTouch
or something like that, and let the ListView
handle the click events.
I hope this helps
EDIT:
for your problem with selecting the item use
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
yourMethod();
}
});
他のヒント
following raukodraug's suggestion and post ListView OnItemClickListener Not Responding?
Another fact as mentioned use bindView
method, I used
view.setClickable(true);
view.setFocusable(true);
the item click kind of works, only if you click on the region marked highlighted in Yellow and the ImageView
. I should be able to figure this out thanks,
Edited
Oh *%#$ Solved it, Needed to set the RelativeLayouts Add State from Children = true;