android - how to change the color of the list items in list view -


i using listview in activity class. i'm not using xml code listview. unable change color of text item in listview.

i changed background color of listview unable change color of list items. got links internet not able figure out. can me code?

my activity class looks this:

listview listview;         // create array of strings, put our listactivity         string[] names = new string[] { "india", "malaysia" };         textview tv = new textview(getapplicationcontext());         tv.settext("select country");         tv.settextcolor(012);          listview = getlistview();         listview.addheaderview(tv);          listview.setcachecolorhint(color.rgb(36, 33, 32));         listview.setbackgroundcolor(color.rgb(225, 243, 253));         this.setlistadapter(new arrayadapter<string>(this,android.r.layout.simple_expandable_list_item_1,names));      } 

above, tv.settextcolor set heading of list items. , not working asking me pass integer value. integer value can pass color? can 1 suggest code changing color of list items?

for having colored listitem,you need custom it.for that,prepare xml file:

custom_listitem.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent" android:layout_height="fill_parent"       android:orientation="vertical">       <textview android:layout_width="fill_parent" android:layout_height="wrap_content"             android:textcolor="#ffffff"             android:id="@+id/list_item"             android:background="#ff0000" <!-- red color -->             />      </linearlayout> 

now have use in adapter like-

listview.setlistadapter(new arrayadapter<string>(this,r.layout.custom_item,r.id.list_item,names)); 

and yes,you can use color.red,color.yellow etc.for default colors,our can use "#3c3c3c" (while using in xml) or color.parsecolor("3c3c3c") (while using programatically) colors other default colors.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -