質問

大丈夫私はこれがListViewとListactivityの問題に関する他の問題のように聞こえるかもしれないことを知っていますが、これは私がこれまでに行ったときに私が持っているので夢中になるつもりです、そしてこれに対する解決策を見つけるためにすべての投稿を検索しましたそれは私を助けるかもしれません。すでに試してみました ListView項目の背景 GetView VS.カスタムCursorAdapterのBINDVIEW?

OKE問題点1 1のListViewは選択/ Fireイベントを許可することはなく、アイテムがクリックされたときに行のハイライトを変更しません。 TestActivityを拡張する標準のListActivityがあり、カスタムTestCursorAdapter extends SimpleCursorAdapter を実装しました。

現在test_list_view.xmlと2番目のrow_view.xmlにあるもののXML側で、私は上記の説明に従って、selectorrow_selector.xmlとして実装します。しかし、問題は1つの行がクリックまたはフォーカスイベントを受け入れないためのものです。私は何が起こっていることがあるかどうかを示すための基本的なトーストを実装しました

@Override
protected void onListItemClick(ListView l, View v , int postion, long idontnow){
    Toast.makeText(getApplicationContext(), "Hello World",  Toast.LENGTH_SHORT ).show();
}
.

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

役に立ちましたか?

解決

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,

enter image description here

Edited

Oh *%#$ Solved it, Needed to set the RelativeLayouts Add State from Children = true;

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top