我试图创建一种EPG布局,我提到了这一点
(Print out ArrayList content in Android TableLayout)
我的问题是,当我尝试添加行时,它们被添加为新行,但是我需要将这些值添加到现有行中。
这是我的XML文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/myTableLayout"
android:layout_width="match_parent"
android:layout_height="354dp"
android:background="#6495ED"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tablerow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text "
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"
/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text" />
</TableRow>
</TableLayout>
我的java文件是
TableLayout table = (TableLayout) findViewById(R.id.myTableLayout);
for(int i=0;i<channel_arraylist.size();i++)
{
TableRow tableRow2=new TableRow(VideoDatabase1.this);
localchannel1= channel_arraylist.get(i);
TextView tvid=new TextView(VideoDatabase1.this);
tvid.setText(""+Integer.toString(localchannel1.getID()));
tableRow2.addView(tvid);
table.addView(tableRow2);
最佳答案
我对你问题的回答。
private ArrayList<String> data = new ArrayList<String>();
private ArrayList<String> data1 = new ArrayList<String>();
private TableLayout table;
data.add("Samsung");
data.add("Apple");
data.add("Pixle");
data.add("Vivo");
data1.add(" $109");
data1.add(" $200");
data1.add(" $399");
data1.add(" $290");
table = (TableLayout)findViewById(R.id.mytable);
for(int i=0;i<data.size();i++)
{
TableRow row=new TableRow(this);
String phone = data.get(i);
String amount = data1.get(i);
TextView tv1=new TextView(this);
tv1.setText(phone);
TextView tv2=new TextView(this);
tv2.setText(amount);
row.addView(tv1);
row.addView(tv2);
table.addView(row);
}