У меня есть ListView, в котором каждая строка содержит флажок и горизонтальное LinearLayout право на флажок. фон линейной компоновки является растяжимым, а сам макет содержит два текстовых окна рядом (большой текст и небольшой текст -sometimes скрыты tho):
То, что я хочу, когда кто-то нажимает на строку, флажок будет переворачивать свой статус, и это происходит. Я никогда не хочу, чтобы строка сама меняла цвет, однако, что происходит сейчас, когда я нажимаю LinearLayout (содержащий текстовые элементы), сама строка и линейный макет меняют цвет на оранжевый,
но я хочу только linearLayout, чтобы textViews менял свой цвет. Мне удалось сделать это с помощью TextView с drwable фон, но здесь он должен быть LinearLayout, потому что он должен содержать два текстовых элемента.
так что мой вопрос в том, как я могу сделать этот heppen, а это значит, что когда кто-то нажимает на linearLayout, LinearLayout изменит свой цвет на оранжевый, без изменения строки? Благодарю!
вот мой row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout11"
android:layout_height="wrap_content"
android:gravity="center_vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent">
<CheckBox
android:paddingLeft="6dp"
android:button="@drawable/custom_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:focusable="false"
android:id="@+id/interest_checkbox">
</CheckBox>
<LinearLayout
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/LinearLayout12"
android:layout_gravity="center_horizontal"
android:paddingLeft="6dp"
android:weightSum="1"
android:paddingRight="6dp"
android:layout_marginRight="6dp"
android:background="@drawable/row_state">
<TextView
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/interest_summary" android:text="Big Text">
</TextView>
<TextView
android:layout_height="wrap_content"
android:textColor="@color/back"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="0dp"
android:id="@+id/TextView11"
android:layout_weight="1"
android:text="small text">
</TextView>
</LinearLayout>
</LinearLayout>
и вот row_state.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="@drawable/row_clicked"
/> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="@android:drawable/editbox_background_normal"
/> <!-- focused -->
<item
android:drawable="@drawable/row"
/> <!-- default -->
</selector>
установите Background of CheckBox тоже с аналогичным списком состояний.. точно так же, как row_state.xml и, вероятно, вы можете это сделать..
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="@drawable//*default checkBox color*/"
/> <!-- pressed -->
<item
android:state_focused="false"
android:drawable="@drawable//*default checkBox color*/"
/> <!-- focused -->
<item
android:drawable="@drawable//*default checkBox color*/"
/> <!-- default -->
</selector>
Вам необходимо переопределить bindView вашего SimpleCursorAdapter:
SimpleCursorAdapter myAdapter = new SimpleCursorAdapter(...) {
public void bindView(View view, android.content.Context context, Cursor cursor) {
final LinearLayout layout = view.findViewById(R.id.somelinearlayout);
// Add an onclick handler to the LinearLayout
layout.setOnClickListener(new OnClickListener() {
// Add click handler that alters the background
});
}
}