Eugene Shmorgun
Eugene Shmorgun

Reputation: 2075

how to change listview's row properties without layout?

Good time! My Android app has so feature that I use ListView in the one of the page of TabHost without layout for ListView. Like that:

    ListView lv = new ListView(this);
    lv.setAdapter(myAdapter);

So I'd like to change some row's properties like text size in the row. So, how can I get access to the properties of the explicit row of ListView to change text size, for example?

Upvotes: 3

Views: 770

Answers (1)

Gopal
Gopal

Reputation: 1719

Use BaseAdapter and modify font size in getView call.

   public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.custom_layout, null);
            // Creates a ViewHolder and store references to the two children views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.text);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // Change text size
        holder.text.setTextAppearance(context,R.style.customStyle);

        return convertView;
    }

    static class ViewHolder {
        TextView text;
    }

And you can use position variable in getView call to change specific row. Hope this help!!!

Upvotes: 2

Related Questions