Wednesday, October 21, 2009

[android-developers] Bold a row in ListView programmatically

I have created a ListView with rows of text+icon. On certain
conditions, I want to BOLD the text on a particular row.

I first tried it out in the On-Click and it works.

myListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View v, int
position,long id) {
TextView b1 = (TextView) v.findViewById
(R.id.itemText);
b1.setTypeface(null, Typeface.BOLD);
Log.i(TAG, "onItemClick ..."+b1.getText());
//b1.setText("testing");
}});


However when I put the codes into a function and call it (I created a
menu item to activate it), the text does not become bold.

public void setBold() {
View v = (View) mySimpleAdapter.getView(2, null,
myListView); // get row 3
TextView tv2 = (TextView) v.findViewById(R.id.itemText);
tv2.setTypeface(null, Typeface.BOLD);
Log.i(TAG, "setBold ..."+tv2.getText());
tv2.setText("testing");
//v.invalidate();
//mySimpleAdapter.notifyDataSetChanged();
}


The Log in setBold function does show up, so I believe the codes in
setBold() are being executed. What is so different about on-Click that
refreshed the ListView but not through the function?

I am using the default ListView and a SimpleAdapter to populate the
List.

Is there something I should add to the setBold() to refresh the view
or is there other better way to change the textView to bold?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments:

Post a Comment