Question

I've a ListView:

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@android:color/background_light" />

I build it:

list = new ArrayList<String>();
list.add("First");
list.add("Second");
ListView listFontView = (ListView) findViewById(R.id.list);
        listFontView.setAdapter(new ArrayAdapter<String>(this, R.layout.row, R.id.textViewList, list));
        listFontView.setOnItemClickListener(this);

How can i do to set different font for any record of this arrayList of string? I would use a font for "First" and another font for "Second".

Help me. Thank you

Was it helpful?

Solution

I don't know if there is an easier or faster way to achieve what you ask for, but to do so, I made my own custom adapter.

For this purpose you can extend BaseAdapter

This tutorial helped me a lot when I needed to make something similar.

Creating a custom adapter

If you give it a shot this way, and you think you might need more info, please let me know.

OTHER TIPS

ListView itself is not responsible for the look of its items. You use a ListAdapter for that. I suggest you watch The World of ListView to understand how to make your own list adapters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top