Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

how i can add custom font to listview

how i can add custom font to listview list_row this the code

package afdal.shealt.com.Adapter;

import afdal.shealt.com.AndalosList; import afdal.shealt.com.R;

import java.util.ArrayList; import java.util.HashMap;

import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView;

public class AndalosAdapter extends BaseAdapter {

private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
int imageResource;
public AndalosAdapter(Activity a, ArrayList<HashMap<String, String>> d, int imageResource) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.imageResource = imageResource;
}

public int getCount() {
    return data.size();
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_row, null);

    TextView title = (TextView)vi.findViewById(R.id.title); // title
    TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

    HashMap<String, String> song = new HashMap<String, String>();
    song = data.get(position);

    // Setting all values in listview
    title.setText(song.get(AndalosList.KEY_TITLE));

// artist.setText(song.get(CustomizedListView.KEY_ARTIST)); duration.setText(song.get(AndalosList.KEY_DURATION));

    thumb_image.setImageResource(imageResource);
    return vi;
}

}

Hi, TO CUSTOMIZE THE TEXT FONT FONT OF THE ITEMS IN YOUR LISTVIEW IS EASY: especially if you're not trying to do it dynamically in Java. --> Simply edit your xml layout file, ie. item_row by adding an attribute to your TextView. For instance you may use textStyle ="bold" or"italic", or textColor ="#f00" or textView ="serif" or "monospace" or textSize ="30sp", etc Let me know if you have any more questions