hiii ... guys ... m新的android開發..我得到這個異常plz幫助我..「
指定的孩子已經有一個家長,你必須調用removeview「。
android textview table佈局在txtAmount.for循環沒有輸入txtAmount來顯示文本..
它顯示我的項目名稱和速度螞蟻我指定textview txtItemName和txtRate respectivly但它不顯示在for循環txtAmount金額文本..顯示以下例外情況。 「指定的孩子已經有父母,您必須調用removeview」。指定的孩子已經有一個家長,你必須調用removeview android textview table layout
public class ConfirmOrder extends Activity {
TextView txtLength;
int length,rate,amount;
String name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.confirmorder);
Intent intent = getIntent();
length=intent.getIntExtra("LENGTH", 0);
rate=intent.getIntExtra("Rate", 0);
amount=intent.getIntExtra("Amount", 0);
name=intent.getStringExtra("Name");
txtLength.setText(String.valueOf(amount));
Log.d("length",""+length);
Log.d("name",""+name);
Log.d("Rate",""+rate);
Log.d("Amount",""+amount);
try
{
TableLayout tv=(TableLayout) findViewById(R.id.table);
tv.removeAllViewsInLayout();
int flag=1;
for(int i=0;i<=10;i++)
{
TableRow tr=new TableRow(ConfirmOrder.this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
if(flag==1)
{
TextView Name=new TextView(ConfirmOrder.this);
Name.setPadding(10, 0, 0, 0);
Name.setTextSize(20);
Name.setText("ItemName");
Name.setTextColor(Color.WHITE);
tr.addView(Name);
TextView Rate=new TextView(ConfirmOrder.this);
Rate.setPadding(10, 0, 0, 0);
Rate.setTextSize(20);
Rate.setText("Rate");
Rate.setTextColor(Color.WHITE);
tr.addView(Rate);
TextView Amount=new TextView(ConfirmOrder.this);
Amount.setPadding(10, 0, 0, 0);
Amount.setTextSize(20);
Amount.setText("Amount");
Amount.setTextColor(Color.WHITE);
tr.addView(Amount);
tv.addView(tr);
final View vline = new View(ConfirmOrder.this);
vline.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 2));
vline.setBackgroundColor(Color.GRAY);
tv.addView(vline);
flag=0;
}
else
{
int l;
TextView[] txtItemName=new TextView[10];
TextView[] txtRate=new TextView[10];
TextView[] txtAmount=new TextView[10];
for(l=0; l<=10; l++)
{
txtItemName[l] = new TextView(this);
txtItemName[l].setTextSize(15);
txtItemName[l].setId(l);
txtItemName[l].setText(name);
tr.addView(txtItemName[l]);
tv.addView(tr);
txtRate[l] = new TextView(this);
txtRate[l].setTextSize(15);
txtRate[l].setId(l);
txtRate[l].setText(String.valueOf(rate));
tr.addView(txtRate[l]);
tv.addView(tr);
txtAmount[l] = new TextView(this);
txtAmount[l].setTextSize(15);
txtAmount[l].setId(l);
txtAmount[l].setText(String.valueOf(amount));
tr.addView(txtAmount[l]);
tv.addView(tr);
}
final View vline1 = new View(ConfirmOrder.this);
vline1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
vline1.setBackgroundColor(Color.WHITE);
tv.addView(vline1);
}
}
}
catch(Exception e)
{
Log.e("log_tag", "Error parsing data "+e.toString());
System.out.println("ERROR : " + e.getMessage());
Log.d("Message",""+e.getMessage());
}
}
}
可以請您發佈您的Logcat嗎? – 2013-02-12 15:43:18