开发者

how to change listview's row properties without layout?

Good time! My A开发者_如何学Cndroid 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?


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!!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜