填充数组的多行列表视图?

时间:2012-05-04 10:37:39

标签: java android

我有三个数组,我想用它们填充列表视图,到现在为止我设法用一个数组和数组适配器填充列表视图,但现在我需要将所有三个数组放在列表视图的每个项目中。 简单的代码可以帮助很多。 提前谢谢。

2 个答案:

答案 0 :(得分:0)

将三个数组合并为一个数组并像以前一样填充

答案 1 :(得分:0)

请参阅此代码以创建自定义适配器

public class ListViewAdapter extends BaseAdapter {


private ArrayList<TimeRecord> record = new ArrayList<TimeRecord>();

TextView txtTime, txtNote;


public ListViewAdapter() {

    record.add(new TimeRecord("38:23", "Feeling good!"));
    record.add(new TimeRecord("49:01", "Tired. Needed more caffeine"));
    record.add(new TimeRecord("26:21", "I’m rocking it!"));
    record.add(new TimeRecord("29:42",
            "Lost some time on the hills, but pretty good."));

}


@Override
public int getCount() {

    // TODO Auto-generated method stub
    return record.size();
}


@Override
public Object getItem(int position) {

    // TODO Auto-generated method stub
    return getItem(position);
}


@Override
public long getItemId(int position) {

    // TODO Auto-generated method stub
    return position;
}


@Override
public View getView(int position , View convertView , ViewGroup parent) {

    // TODO Auto-generated method stub

    if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        convertView  = inflater.inflate(R.layout.row_xml, parent, false);
    }
    TimeRecord time = record.get(position);

    txtTime = (TextView) convertView.findViewById(R.id.txtTime);
    txtTime.setText(time.getTime());

    txtNote = (TextView) convertView.findViewById(R.id.txtNote);
    txtNote.setText(time.getNote());

    return convertView;
}
}