填充阵列多行列表视图? [英] Multi-line list view populated with arrays?

查看:123
本文介绍了填充阵列多行列表视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个阵列,我想填充他们的列表视图,到现在我设法填充列表视图与一个阵列和阵列适配器,但现在我需要把所有三个阵列中的列表视图中的每一个项目。
简单code将帮助很多。
谢谢你在前进。

I have three arrays and I want to populate list view with them, till now I managed to populate list view with one array and array adapter, but now I need to put all three arrays in every item of list view. Simple code would help lots. Thank you in advance.

推荐答案

转寄此code创建自定义适配器

Refer this code to create Custom Adapter

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;
}
}

这篇关于填充阵列多行列表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆