带颜色的android简单列表视图

带颜色的android简单列表视图,android,android-layout,Android,Android Layout,我在活动中显示字符串列表,如下所示: protected void onResume() { // TODO Auto-generated method stub super.onResume(); String[] lKeys = new String[mKey.size()]; int i = 0; if (lKeys != null) { for (Iterator<String> ite = mKey.iter

我在活动中显示字符串列表,如下所示:

    protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    String[] lKeys = new String[mKey.size()];
    int i = 0;
    if (lKeys != null) {
        for (Iterator<String> ite = mKey.iterator(); ite.hasNext();) {
            String element = ite.next();
            if (element.contains("Data")) {
                lKeys[i++] = element;
            } else {
                lKeys[i++] = element + ": " + mValue.get(element);
            }               
        }
    }
    //
    this.setTitle(mTitle);
    setListAdapter(new ArrayAdapter<String>(this,R.layout.popupactivity,lKeys));
protectedvoid onResume(){
//TODO自动生成的方法存根
super.onResume();
String[]lKeys=新字符串[mKey.size()];
int i=0;
如果(lKeys!=null){
for(迭代器ite=mKey.Iterator();ite.hasNext();){
String元素=ite.next();
if(元素包含(“数据”)){
lKeys[i++]=元素;
}否则{
lKeys[i++]=element+“:”+mValue.get(element);
}               
}
}
//
本文件为setTitle(mTitle);
setListAdapter(新的ArrayAdapter(this,R.layout.popupactivity,lKeys));
这个xml是什么

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tvResults"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textColor="#000000"
    android:background="#ffffff"
    android:layout_marginLeft="5dp"
    android:textSize="12sp" 
    android:padding="5dp" >
</TextView>

这很好,但我需要在列表的行中添加一些颜色。 谁能帮我


非常感谢!

通过扩展SimpleAdapter并重写getView()方法并将背景色应用于当前视图行,您可以向ListView的每一行的背景添加不同的颜色。之后使用自定义适配器作为列表

public class CustomList extends SimpleAdapter {
private int[] colors = new int[] { 0x30ADD8E6, 0x30800080 };

public CustomList(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
    super(context, items, resource, from, to);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  View view = super.getView(position, convertView, parent);
  int colorPos = position % colors.length;
  view.setBackgroundColor(colors[colorPos]);
  return view;
}}

通过扩展SimpleAdapter并重写getView()方法,可以向ListView的每一行的背景添加不同的颜色,并将背景颜色应用于当前视图行。之后使用自定义适配器作为列表

public class CustomList extends SimpleAdapter {
private int[] colors = new int[] { 0x30ADD8E6, 0x30800080 };

public CustomList(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
    super(context, items, resource, from, to);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  View view = super.getView(position, convertView, parent);
  int colorPos = position % colors.length;
  view.setBackgroundColor(colors[colorPos]);
  return view;
}}

谢谢Priebe,我使用ScrollView中的tableLayout完成工作谢谢Priebe,我使用ScrollView中的tableLayout完成工作