I'm trying to apply styles (bold, specifically) to selected items in a ListView. To that end, I've assigned the android:bufferType="spannable" attribute to its individual TextView elements, so that the code can obtain a Spannable like this:
Since, you are using ArrayAdapter class directly I am not sure of how you would control the formatting of the individual TextView; have not tried anything like this before.
Usually, I would extend an appropriate Adapter class(e.g.: BaseAdapter) and override all its methods to cater to my needs. I would've put the following code inside getView() method of my adapter, which is called by the framework once for every row to be drawn, and applied these styles conditionally there.
Note: getView() code is not optimized but it conveys what I am trying to say
Joined: Mar 22, 2005
That worked like a charm with just a few minor tweaks. Kinda cool that it's possible to style each row of the list individually. Not that one would (or should) do that, but it's nice to know that it's possible :-)
Ulf Dittmer wrote:That worked like a charm with just a few minor tweaks. Kinda cool that it's possible to style each row of the list individually. Not that one would (or should) do that, but it's nice to know that it's possible :-)
Yes, that way, recycled views are used for newer rows instead a new View Object, for every row to be drawn.(Total number of View objects created would be number of rows visible on the screen at a time)
There is still one more optimization you can apply here using the ViewHolder pattern. This would reduce the findViewById(..) calls which are considered expensive too.(Note that this would affect the performance had the layout of your row been a little more "dense" or complex and also if the number of rows in the list were high).