0

I have a ListView. When I try to make it's row's textview bold - it falls. I try:

ListView list = (ListView) findViewById(R.id.my_list);

list.setAdapter(someListAdapter);

((TextView) list.getChildAt(0).findViewById(R.id.first_name)).setTypeface(null, Typeface.BOLD);

I need to do this with only one (headers) row's textviews.

Maximus
  • 471
  • 1
  • 10
  • 25
  • Did you try to change it inside the adapter? Accessing listview children directly is not a good idea since the views can be reused. You can also use `list.addHeader(view)`; – Flávio Faria Nov 16 '12 at 20:48

1 Answers1

0

I need to do this with only one (headers) row's textviews.

Try calling this before calling addHeaderView(view):

((TextView) view.findViewById(R.id.first_name)).setTypeface(null, Typeface.BOLD);

If you not using addHeaderView(), extend your adapter and add a snippet of code like this to getView():

if(position == 0)
    ((TextView) convertView.findViewById(R.id.first_name)).setTypeface(null, Typeface.BOLD);
else
    ((TextView) convertView.findViewById(R.id.first_name)).setTypeface(null, Typeface.NORMAL);

(I recommend using a ViewHolder, rather than calling findViewById() repeatedly. This is just for a quick example.)

Sam
  • 86,580
  • 20
  • 181
  • 179
  • Sam, how to bind data to addHeaderView(view, data, flag)? In which format it must to be? – Maximus Nov 16 '12 at 21:51
  • Read [this answer](http://stackoverflow.com/a/12481083/1267661) for how to use `addHeaderView(View, Object, boolean)`. – Sam Nov 16 '12 at 22:03