0

クリック可能なリストアイテムの外観を再構築する必要があります。

したがって、私はこのxmlコードを持っています:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical" >

<TextView
    android:id="@+id/tv_changeRoomLabel"
    style="?android:attr/listSeparatorTextViewStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/label_optionChangeName" />

<include
    android:id="@+id/tv_btn_changeRoom"
    layout="@android:layout/simple_list_item_1"
    android:background="@android:drawable/btn_default"
    android:clickable="true" />
</LinearLayout>

タグに追加するためにさまざまなことを試しましたが、常に同じです。リストアイテムをクリックしても、フィードバックが表示されません。simple_list_itemの背景色は、通常のListViewを使用する場合のように変化しないことを意味します。それにもかかわらず、少なくともonClick()が実行されます。

何か案は?

PS simple_layout_activate_1に出くわしましたが、API 11なので、使用できません。私はmintarget7を持っています。

編集:javacode

TextView options = (TextView) findViewById(R.id.tv_btn_changeRoom);
    options.setText(m_model.getRoomName(m_roomId));
    options.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //do sth
        }
    });
4

1 に答える 1

0

Ok。ディスカッションでのコメントによると、あなたtextViewが選ばれたときにあなた自身のセレクターが欲しいと思います

このために、レイアウトファイルを介してこれを行うことができます。を使用してレイアウトを行うのは非常に簡単ですselector

textViewこれに合わせてデザインを変更します。

<TextView
    android:id="@+id/tv_changeRoomLabel"
    android:background="@drawable/textBackSelector"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/label_optionChangeName" />

ドローアブルフォルダにファイルを作成し、名前を付けますtextBackSelector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" android:color="THE_COLOR_YOU_WANT_WHEN_PRESSED"/>
    <item android:state_selected="true" android:color="THE_COLOR_YOU_WANT_WHEN_SELECTED"/>
    <item android:color="DEFAULT_BACKGROUND_COLOR_OF_TEXTVIEW"/>

</selector>

上記のxmlは、選択されたときにtextViewの背景を処理します。

お役に立てば幸いです。

ありがとう

于 2013-01-23T03:23:50.487 に答える