打印出Android TableLayout中的ArrayList内容 [英] Print out ArrayList content in Android TableLayout

查看:34
本文介绍了打印出Android TableLayout中的ArrayList内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 ArrayList:

I have this ArrayList:

 ArrayList<Double> debtList = datasource.debtList;
 ArrayList<Double> feeList = datasource.feeList;

我将如何在 TableLayout 中循环打印这两个列表(格式无关紧要)?这是布局:

How would I print out these two Lists side by side (formatting doesn't matter) in a TableLayout in a loop? Here is layout:

 TableLayout table = (TableLayout) findViewById(R.id.myTableLayout);

推荐答案

好的,你有两个arraylists DebtList 和feeList,我假设两个arraylist 包含相同数量的元素,现在遍历这个列表,创建表格行添加两个textViews到表格行,并将 tablerow 添加到 tableLayout,因此您可以执行以下操作:

Ok, you have two arraylists debtList and feeList, I assume both the arraylist contains equal number of elements, now iterate through this list, Create Table Row add two textViews to table row, and add tablerow to the tableLayout, so you can do following:

ArrayList<Double> debtList = datasource.debtList;
ArrayList<Double> feeList = datasource.feeList;
TableLayout table = (TableLayout) findViewById(R.id.myTableLayout);
for(int i=0;i<debtList.size();i++)
{
    TableRow row=new TableRow(this);
    double debt = debtList.get(i);
    double fee = feeList.get(i);
    TextView tvDebt=new TextView(this);
    tvDebt.setText(""+debt);
    TextView tvFee=new TextView(this);
    tvFee.setText(""+fee);
    row.addView(tvDebt);
    row.addView(tvFee);
    table.addView(row);
}

这篇关于打印出Android TableLayout中的ArrayList内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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