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

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

问题描述

我有这样的ArrayList

 的ArrayList<双> debtList = datasource.debtList;
 ArrayList的<双> feeList = datasource.feeList;
 

我将如何打印出这两个列表中的一个TableLayout并排(格式并不重要)在一个循环?这里是布局:

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

解决方案

好吧,你有两个的ArrayLists debtList和feeList,我认为无论是ArrayList包含相同数量的元素,现在遍历这个列表,创建表行添加两个textViews为表行,并添加tablerow的到tableLayout,这样你就可以做到以下几点:

 的ArrayList<双> debtList = datasource.debtList;
ArrayList的<双> feeList = datasource.feeList;
TableLayout表=(TableLayout)findViewById(R.id.myTableLayout);
的for(int i = 0; I< debtList.size();我++)
{
    的TableRow行=新的TableRow(本);
    双债务= debtList.get(ⅰ);
    双费= feeList.get(我);
    TextView的tvDebt =新的TextView(本);
    tvDebt.setText(+债务);
    TextView的tvFee =新的TextView(本);
    tvFee.setText(+手续费);
    row.addView(tvDebt);
    row.addView(tvFee);
    table.addView(行);
}
 

I have this ArrayList:

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

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

解决方案

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

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

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