Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView individual item styling

Tags:

android

I am developing an android app, and in one fragment, I already have a listview and have a set of items that will be added to this listview via an arrayadapter. However, I was requested to dynamically color some list items based on a particular property in the original database, specifically bold only those elements to highlight them. Is there any possible way to acheve this with the arrayAdapter class, or if not, considering this is a simplistic use case, what can I do to achieve this

like image 630
Kavinda Keshan Rasnayake Avatar asked Dec 20 '25 15:12

Kavinda Keshan Rasnayake


1 Answers

It's very easy to handle this problem you just have to put a condition in your adapter and if that condition is true you just have to customize your item as it's asked from you .

  if(condition)
    {
        view.setBackgroundColor(activity.getResources().getColor(R.color.White));

    }

And if you want to set a TextView as Bold programmatically in your adapter check your condition and set it like below :

textView.setTypeface(null, Typeface.BOLD);
like image 193
Ahlem Jarrar Avatar answered Dec 23 '25 04:12

Ahlem Jarrar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!