简体   繁体   中英

How to increase font size in JUST one item in a Listview / Arraylist

I have a listView and an arrayList that I'd like to increase the font size of just one item (the first one) can anyone point me towards an example of how this might be accomplished?

(I've tried googling and searching SO but I can't seem to find an example anywhere)

Source:

ListView list = (ListView) findViewById(R.id.list);
        ArrayAdapter<String> adapt = new ArrayAdapter<String>(
                Example.this, android.R.layout.simple_list_item_1, list);
        list.setAdapter(adapt);

You should implement your own adapter to fulfill this. Here is the sample

private class MyAdapter extends BaseAdapter {

    private ArrayList<String> mTexts;
    private LayoutInflater mInflater;

    public MyAdapter(Context context, ArrayList<String> text) {
        mInflater = LayoutInflater.from(context);
        mTexts = text;
    }

    @Override
    public int getCount() {
        return mTexts.size();
    }

    @Override
    public Object getItem(int position) {
        return mTexts.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.layout_list, parent, false);
        }

        TextView tv = (TextView) convertView.findViewById(R.id.tv);
        if (position == 0) tv.setTextSize(60);
        else tv.setTextSize(25);


        return convertView;
    }
}

Hope it'll help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM