這是從一些名單
public static TableRow[] Create(List<Apartment> list){
TableRow[] rows=null;
try{
rows=new TableRow[list.size()*3];
int i=0;
for(Apartment ap : list){
rows[3*i]=new TableRow(activity);
rows[3*i+1]=new TableRow(activity);
rows[3*i+2]=new TableRow(activity);
rows[3*i].setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
rows[3*i+1].setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
rows[3*i+2].setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
EditText txtMainInform=new EditText(activity);
//txtMainInform.setText(ap.GetMainInformation());
txtMainInform.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
txtMainInform.setText("vvvvvvvvvvvvvvvvvvvv");
txtMainInform.setVisibility(1);
rows[3*i].addView(txtMainInform);
rows[3*i].setVisibility(1);
TextView txtMoreInform=new TextView(activity);
txtMoreInform.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
rows[3*i+1].addView(txtMoreInform);
ImageButton imbGallery=new ImageButton(activity);
imbGallery.setClickable(true);
imbGallery.setEnabled(true);
imbGallery.setBackgroundResource(R.drawable.gallery_icon);
ImageButton imbCall=new ImageButton(activity);
imbCall.setBackgroundResource(R.drawable.phone);
ImageButton imbMap=new ImageButton(activity);
imbMap.setBackgroundResource(R.drawable.map);
rows[3*i+2].addView(imbGallery);
rows[3*i+2].addView(imbCall);
rows[3*i+2].addView(imbMap);
rows[3*i+2].setEnabled(true);
i++;
}
}
catch(Exception e){
}
return rows;
}
有我添加創建行功能ImageButtons-這是在OnCreate功能的一部分
TableRow[] rows=ResultCreator.Create(list);
TableLayout table=(TableLayout)this.findViewById(R.id.result_layout);
for(TableRow row:rows){
table.addView(row,new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
}
我TableLayout是其他的LinearLayout裏面,使不同?
謝謝
你可以顯示你動態添加圖片按鈕的代碼片段嗎? – 2010-09-10 16:17:31
我放下了不起作用的代碼。幫幫我 ? :( – msretractor 2010-09-10 21:11:44