无法以表格格式打印数组元素

时间:2012-11-23 12:08:44

标签: android

我正在尝试以表格格式打印显示数组元素,但无法以表格格式获取元素,输出如下所示

Name     Address  Phone
Ramu     7/g      45464 Raju 1-6

As shown in the above, the name will come under the Name Column in the table, i wrote code as below          

TableROW t=new TableRow(this);
for(int i = 0; i<Programlist.length;i++)
{

 if(i%3==0)
 {
    String Name=Programlist[i];// Getting the First Element Of the Array
    TextView P_Name=new TextView(this);
   P_Name.setText(Name);//Attaching to the textview 
   P_Name.setPadding(0, 2, 3, 5);
    t.addView(P_Name);//Adding to the Row
  }
  else if(i%3==1)
  {
String Address=Programlist[i]+"\n";// Getting Element 
    TextView Adrs=new TextView(this);// Attaching to the Textview 
    Adrs.setText(Address);
    Adrs.setPadding(2,5, 3, 2);
    t.addView(Adrs);
    Continue;

   }
   else
   {
    String phone=Programlist[i];
    TextView u_phone=new TextView(this);
    u_phone.setText(phone);
    u_phone.setPadding(2,5, 3, 2);// Space Between the columns Data 
    t.addView(u_phone);// Attaching to the Table Row
    continue;
   }

}
tableLayout.addView(tdata, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.MATCH_PARENT));

最后,我试图将表格附加到表格中显示我编写的代码的最后一行。所以请帮帮我

0 个答案:

没有答案