在customadapter android中为行着色
好的,到目前为止我已经创建了这个,并且我的项目正在显示。假设我在一个数组中包含与行一样多的元素的键值。如果我有 16 行,那么我的数组就有 16 个元素。我想检查 array[0] 并根据值 setColor 到第一行,然后检查 array[1] 并 setColor 到下一行,依此类推。谁能帮我:
public class SimpleAdapter extends ArrayAdapter<String>{
private final Context context;
private String data[] = null;
public SimpleAdapter(Context context, String[] data) {
super(context, R.layout.row, data);
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.row, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.text1);
textView.setText(data[position]);
return rowView;
}
}
Ok so far I have created this, and my items are being displayed. Lets suppose that I am having the key values in an array with as many elements as the rows. If I have 16 rows, then my array has 16 elements. I want to check the array[0] and depending on the value setColor to first row, then check array[1] and setColor to next row and so on. Can anyone help me:
public class SimpleAdapter extends ArrayAdapter<String>{
private final Context context;
private String data[] = null;
public SimpleAdapter(Context context, String[] data) {
super(context, R.layout.row, data);
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.row, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.text1);
textView.setText(data[position]);
return rowView;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 getView() 中你可以有类似的东西:
In getView() you can have something like:
在数组中定义颜色/(背景可绘制)非常简单。就像
然后使用下面的行
It is simple define your
color/(background drawable)
in an array. likethen just use the below lines