1

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

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

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

4

0 回答 0