私は物事がうまくいくように努力しましたが、何の成功もありませんでした。Android - カスタムリストビューとハイライト
私は3つのテキストビューを表示し、私の手のカスタムアダプターを追加し、正しく動作させるカスタムリストビューを実装しました。私はregisterForContextMenu(listviewのビュー)を実行しました。私のアイテムの周りをハイライトし、それを長く押すと同じことが起こり、メニューが表示されます。はい。次に、私はカスタムリストビューの中にあるボタンを追加して、特定のものが起こった場合には1つの色を表示し、別のものを表示します。私のカスタムアダプタを変更してボタンを組み込み、色の変更ロジックを設定した後、アイテムを長押ししても強調表示はなくなりましたが、コンテキストメニューは保持されます。
どうしてですか?
私はStackとGoogleで多くの検索を試みましたが、見つけたすべての解決策は自分のアプリでは機能していませんでした。私もカスタムセレクタを挿入しようとしました、それは正常に私のリストビューのデザインからボタンを除外、私はボタンが原因だと思うが動作しますが、私はこの問題を解決する方法を見つけることができません。ボタンの「背景」 - 「ドロウアブル」に関連するものがあると思いますが、私はあなたに何か助けを求めるためにここにいます。
ありがとうございます。
いくつかのコードを、それはあなたが興味ことができる場合:
listviewdesign.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:layout_centerVertical="true"
android:gravity="center"
/>
<TextView
android:id="@+id/text2"
android:singleLine="false"
android:maxEms="8"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_toLeftOf="@+id/text3"
android:layout_toRightOf="@+id/text1"
android:layout_centerVertical="true"
android:gravity="center"
/>
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/btn1"
/>
<Button
android:id="@+id/btn1"
android:layout_width="10px"
android:layout_height="10px"
android:layout_alignParentRight="true"
android:layout_marginTop="20dp"
/>
</RelativeLayout>
mainactivitylayout.xml:
<LinearLayout ...>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@android:id/list"
(when I add selector: android:listSelector="@xml/myselector")
android:clickable="false"
/>
</LinearLayout>
万全を期すために、私のセレクタ:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
class="class of project">
<item android:state_pressed="true"
android:drawable="@drawable/pressed"/>
<item android:state_focused="true"
android:drawable="@drawable/focused"/>
<item android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/normal"/>
<item android:drawable="@drawable/normal"/>
</selector>
ここで、tホースドローイング可能なアイテムは正しく設定されています:
<resources>
<drawable name="pressed">#FF00A5FF</drawable>
<drawable name="focused">#FF0000FF</drawable>
<drawable name="normal">#00000000</drawable>
</resources>
ありがとう!
する必要があります...私がしようとしたが、それはうまくいきませんでしたか? – pippo
myselector.xmlをドロウアブルフォルダに配置する必要があります。上記のコードを使用すると動作します。 –
私は試してみましたが、うまくいきません...クリック可能な領域が変更されていると思います。特定のポイントではアイテム全体がハイライト表示されますが、行の「カジュアル」を押すと機能しませんいくつかの点では:私は特に1つの項目と他の1つの境界線に気づいた) – pippo