How to set ListView selected item alternet text color in android

KousiK

I have a custom listview with a imageview and an textview. I want when user select a item the textview color should change and all the other textview should remain default.

here are my xmls

ListView.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="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listViewBell"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:choiceMode="singleChoice"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" />

</LinearLayout>

ListViewItems.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dip" >

    <TextView
        android:id="@+id/txt_bell_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/rihanna_love_the_way_lie"
        android:textColor="@color/black"
        android:textSize="15sp"
        android:textStyle="bold"
        android:typeface="sans" />

    <ImageView
        android:id="@+id/list_bell_image"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:src="@drawable/bronze_bell" />
</RelativeLayout>
vipul mittal

Create following button_text.xml in drawable

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:color="#ffff0000"/> <!-- pressed -->
    <item android:state_focused="true"
          android:color="#ff0000ff"/> <!-- focused -->
    <item android:color="#ff000000"/> <!-- default -->
</selector>

Change your text view's textColor to:

  <TextView
        android:id="@+id/txt_bell_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/rihanna_love_the_way_lie"
        android:textColor="@color/button_text" //point to that xml
        android:textSize="15sp"
        android:textStyle="bold"
        android:typeface="sans" />

You can read about color state list here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android ListView. How to change background color of manually selected item

From Dev

How to color selected item of ListView on android at onListItemClick method

From Dev

How to "set" a selected item in a ListView

From Dev

How to set Text in Textview when Click on selected item in Listview?

From Dev

How to set the Selected Item's text color in Html.Listbox

From Dev

Android listview item not showing selected color

From Dev

How to change the Foreground Color of ListView Selected Item

From Dev

How to change the Foreground Color of ListView Selected Item

From Dev

How to change selected listview item color

From Dev

How to set color of nth list item in listview android

From Dev

Android ListView set selected item highlight with default

From Dev

How to set spinner selected item to edit text on editTextFocusChange- Android

From Dev

Android change listview item text color

From Dev

How to set first item as selected in listview kendoui

From Dev

how take text from selected listview item

From Dev

How to set color to selected item at TreeView

From Dev

How to set the selected item color in the spinner?

From Dev

How to set the selected item color in the spinner?

From Dev

How to change the text color of a ListView item?

From Dev

How can I change default background color of a selected ListView item in Android?

From Dev

Android How to add icon on each listvIew list item and change the text color,Background color

From Dev

Change listview row item background color and text color in android

From Dev

How to set the selected text background color of TextView

From Dev

How to set the selected text background color of TextView

From Dev

How to add color to last item in ListView - Android?

From Dev

Android, color an item of a listView

From Dev

How do I change the color of a selected item on a ListView?

From Dev

How to change color of the selected ListView item [WP8.1]

From Dev

How to change Highlight color of the selected ListView item in UWP (Windows 10)

Related Related

  1. 1

    Android ListView. How to change background color of manually selected item

  2. 2

    How to color selected item of ListView on android at onListItemClick method

  3. 3

    How to "set" a selected item in a ListView

  4. 4

    How to set Text in Textview when Click on selected item in Listview?

  5. 5

    How to set the Selected Item's text color in Html.Listbox

  6. 6

    Android listview item not showing selected color

  7. 7

    How to change the Foreground Color of ListView Selected Item

  8. 8

    How to change the Foreground Color of ListView Selected Item

  9. 9

    How to change selected listview item color

  10. 10

    How to set color of nth list item in listview android

  11. 11

    Android ListView set selected item highlight with default

  12. 12

    How to set spinner selected item to edit text on editTextFocusChange- Android

  13. 13

    Android change listview item text color

  14. 14

    How to set first item as selected in listview kendoui

  15. 15

    how take text from selected listview item

  16. 16

    How to set color to selected item at TreeView

  17. 17

    How to set the selected item color in the spinner?

  18. 18

    How to set the selected item color in the spinner?

  19. 19

    How to change the text color of a ListView item?

  20. 20

    How can I change default background color of a selected ListView item in Android?

  21. 21

    Android How to add icon on each listvIew list item and change the text color,Background color

  22. 22

    Change listview row item background color and text color in android

  23. 23

    How to set the selected text background color of TextView

  24. 24

    How to set the selected text background color of TextView

  25. 25

    How to add color to last item in ListView - Android?

  26. 26

    Android, color an item of a listView

  27. 27

    How do I change the color of a selected item on a ListView?

  28. 28

    How to change color of the selected ListView item [WP8.1]

  29. 29

    How to change Highlight color of the selected ListView item in UWP (Windows 10)

HotTag

Archive