Put Color In Listview Dymically
I have show Array in listview. with black text color. if i using android.R.color.black it will give runtime error. this is my code. list1 =(ListView)findViewById(R.id.scoreView1);
Solution 1:
list1.setAdapter(new ArrayAdapterthis,android.R.layout.simple_list_item_1,R.color.TextColor,datalist1));
You are using this constructor for the array adapter. The third argument is
textViewResourceId The id of the TextView within the layout resource to be populated
and you are giving TextColor. You should provide layout id.
Solution 2:
I had been pursuing the same problem for some time. Instead of using custom adapter I persisted with using Android.Resource.Layout.TwoLineListItem for my view adapter. My hack way of achieving text color changes dynamically is by declaring a dummy textview in the GetView method of the ListViewAdapter.
code example here:
TextView tmptxt = view.FindViewById<TextView> (Android.Resource.Id.Text2);
tmptxt.Text = glt.Genre; // my source for the displayed text in the second line of the listview item.
tmptxt.SetTextColor(Android.Graphics.Color.LightGreen);
glt.Genre = tmptxt.Text;
view.FindViewById<TextView> (Android.Resource.Id.Text1).Text = glt.Title;
view.FindViewById<TextView> (Android.Resource.Id.Text2).Text = (glt.Genre); // now displayed with lightgreen text color
return view;
Post a Comment for "Put Color In Listview Dymically"