Reputation: 39
final TableRow tr1_vin_details = new TableRow(this);
inspStatus = new ImageView(this);
tr1_vin_details.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//TableRow tr = (TableRow) v.getParent();
TableRow lTableRow = ((TableRow) v);
TextView lTextView = (TextView) lTableRow.getChildAt(1);
vinNum = lTextView.getText().toString();
theTag = (Integer) v.getTag();
Intent intent = new Intent(DeliveryInspectionActivity.this, ExceptionsActivity.class);
//intent.putExtra("Row ID of a particular selected row:", rowId);
intent.putExtra("Tag value", theTag);
startActivityForResult(intent, 0);
} });
Now I want to sending the row id(theTag) value to nextActivity, and in onActivityResult I want to add some data coming from NextActivity. Code is
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (resultCode == RESULT_OK) {
id_row = data.getIntExtra("id of row:", 0);
String str = String.valueOf(id_row);
Toast.makeText(this, "You have selected row: " + " " + str, Toast.LENGTH_SHORT).show();
int num_exceptions = data.getIntExtra("Number Of Exceptions", 0);
TextView area_tv = new TextView(this);
TextView type_tv = new TextView(this);
TextView severity_tv = new TextView(this);
if(num_exceptions > 0){
inspStatus.setBackgroundResource(R.drawable.ir_vin_red_check);
tv_area.setText(Html.fromHtml("<br> Area: "));
tv_area.setTextColor(Color.BLACK);
tv_type.setText(Html.fromHtml("<br> Type: "));
tv_type.setTextColor(Color.BLACK);
tv_severity.setText(Html.fromHtml("<br> Severity: "));
tv_severity.setTextColor(Color.BLACK);
openedRow1.removeAllViews();
openedRow1.addView(tv_area);
openedRow1.addView(tv_type);
openedRow1.addView(tv_severity);
openedRow2.removeAllViews();
openedRow2.addView(area_tv);
openedRow2.addView(type_tv);
openedRow2.addView(severity_tv);
tl_skiddetails.addView(openedRow1, id_row);
tl_skiddetails.addView(openedRow2, id_row);
}
}
}
Now my question is I want to add openedRow1 & openedRow2 rows to table layout in onCreate method of FirstActivity when onclick of togglebutton in firstactivity
Where should I add these rows, in onActivityResult or onCreate method...? When I am adding this in OnActivityResult, the app is force closed.
06-04 12:40:58.216: E/AndroidRuntime(1642): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { (has extras) }} to activity {net.mss.palsapp/net.mss.palsapp.DeliveryInspectionActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Please help me... I am struggling with this issue from a long...
Upvotes: 0
Views: 230
Reputation: 6866
If u want to dynamically add table rows to the table layout follow the code below
// Get the TableLayout
TableLayout tl = (TableLayout) findViewById(R.id.maintable);
// Create a TableRow and give it an ID
TableRow tr = new TableRow(this);
tr.setId("unique id for table row");
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
// Create a TextView to house the name of the province
TextView labelTV = new TextView(this);
labelTV.setId("unique id");
labelTV.setText("your text");
labelTV.setTextColor(Color.BLACK);
labelTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
Upvotes: 1