<转>Android ListView中如何使得不用的行字体显示不同的颜色
2011-03-25 17:01
489 查看
本文转载于gaomingjun的博客 http://gaomingjun.javaeye.com/blog/808773 ,转载注明出处
ListView形成的每一步是在Adapter中进行的,我们要是不用的行的字体颜色不一样或者背景不一样,我们只要在adpter的getItemView中修改我们的代码就行了。
以前通常的做法是:
1,看convertView是不是为null,如果为null,我们将新建一个view,为其制定布局文件;如果不为null,我们将convertView.getTag()赋给该view.
2,设定该view的内容。
ChildItemView childItemView = null;
if (convertView == null) {
LayoutInflater mInflater_ = LayoutInflater.from(mContext);
//set the place for the child item view
convertView = mInflater_.inflate(R.layout.expandablechildrenlayout, null);
childItemView = new ChildItemView();
convertView.findViewById(R.id.expandable_children_text);
childItemView.childtitle = (TextView) convertView.findViewById(R.id.expandable_child_title);
convertView.setTag(childItemView);
} else {
//get the child item
childItemView = (ChildItemView) convertView.getTag();
}
现在我们的做法是不管convertView是不是为null,我们根据自己的需要为其设置布局文件,然后设定该view的内容。
if(itemChild.mRead.equals("0")){
LayoutInflater mInflater_ = LayoutInflater.from(mContext);
//set the place for the child item view
convertView = mInflater_.inflate(R.layout.expandablechildrenlayout, null);
childItemView = new ChildItemView();
childItemView.childtitle = (TextView) convertView.findViewById(R.id.expandable_child_title);
}else{
LayoutInflater mInflater_ = LayoutInflater.from(mContext);
//set the place for the child item view
convertView = mInflater_.inflate(R.layout.expandablechildrenlayoutbold, null);
childItemView = new ChildItemView();
childItemView.childtitle = (TextView) convertView.findViewById(R.id.expandable_child_title);
}
最后设定值
childItemView.childtitle.setText(inforText.toString());
ListView形成的每一步是在Adapter中进行的,我们要是不用的行的字体颜色不一样或者背景不一样,我们只要在adpter的getItemView中修改我们的代码就行了。
以前通常的做法是:
1,看convertView是不是为null,如果为null,我们将新建一个view,为其制定布局文件;如果不为null,我们将convertView.getTag()赋给该view.
2,设定该view的内容。
ChildItemView childItemView = null;
if (convertView == null) {
LayoutInflater mInflater_ = LayoutInflater.from(mContext);
//set the place for the child item view
convertView = mInflater_.inflate(R.layout.expandablechildrenlayout, null);
childItemView = new ChildItemView();
convertView.findViewById(R.id.expandable_children_text);
childItemView.childtitle = (TextView) convertView.findViewById(R.id.expandable_child_title);
convertView.setTag(childItemView);
} else {
//get the child item
childItemView = (ChildItemView) convertView.getTag();
}
现在我们的做法是不管convertView是不是为null,我们根据自己的需要为其设置布局文件,然后设定该view的内容。
if(itemChild.mRead.equals("0")){
LayoutInflater mInflater_ = LayoutInflater.from(mContext);
//set the place for the child item view
convertView = mInflater_.inflate(R.layout.expandablechildrenlayout, null);
childItemView = new ChildItemView();
childItemView.childtitle = (TextView) convertView.findViewById(R.id.expandable_child_title);
}else{
LayoutInflater mInflater_ = LayoutInflater.from(mContext);
//set the place for the child item view
convertView = mInflater_.inflate(R.layout.expandablechildrenlayoutbold, null);
childItemView = new ChildItemView();
childItemView.childtitle = (TextView) convertView.findViewById(R.id.expandable_child_title);
}
最后设定值
childItemView.childtitle.setText(inforText.toString());
相关文章推荐
- <Android+Java>Ecplise中Package Explorer显示空白异常及字体更改
- 如何在table的<td>中限制显示的字数
- Android ListView中设置的字体颜色显示错乱问题 && SparseArray<E>的使用
- <p>这段文字用的是缺省的字体颜色。</p>
- <font size=xx.pt> 于world中字体大小的对应关系
- bootstrap-table.js如何根据单元格数据不同显示不同的字体的颜色
- <img src="中文文件名" /> 无法显示图片,图片名改成英文就可以显示;试了下在电脑桌面写了个HTML测试下,可以显示中文名称的图片,解决方法
- <Garry和图表第二次约会>HighCharts, Android传数据(可以不用ajax你造吗)
- 如何在前台使用<%#eval( )%> 传递多个参数
- sp使用<c:choose>标签来控制内容显示
- <C++>获取并显示当前时间
- <如何创建一个实体历史> 时间维度 让 1:n的 产生新的实体 或者关系
- 你是如何成为 Lisp 程序员的<转>
- <Linux+Qt>设置双视频显示及切换
- 同一个TextView如何显示不同颜色的文字、字体大小、字体样式
- 如何让<s:doubleselect>标签的两个下拉框在一行显示
- <input type="button" style="display:none">隐藏按钮显示
- <input type="file" />浏览时只显示指定文件类型
- <%$ %> <%# %> <%= %>的不同
- <蓝牙BLE>如何调整cc2540的发射功率