0

I have a form with a lot of fields. After call a new Intent (camera) and back to main activity, all fields are filled. OK.

But tablelayout looses inner TableRows. Why? Is there no way to keep tablerows?

tableMaterialObra = (TableLayout)findViewById(R.id.tlMaterialObra);
TableRow tr = new TableRow(this);
CheckBox cb = new CheckBox(this);
tr.addView(cb);
tableMaterialObra.addView(tr);
BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

0

If you create TableLayout in oncreate() method and donot do anything in onResume() method then none of the row will be lost

SampleCode

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class RelativeLayoutTesting extends ActivityGroup implements OnClickListener{
    TextView choosenGroup;
    android.widget.RelativeLayout currentView = null;
    ArrayList<String> logpoint = null;
    TableLayout tableMaterialObra;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );


        // set the relative layout as our view 
        setContentView(R.layout.my_table);
        tableMaterialObra = (TableLayout)findViewById(R.id.my_table);
        TableRow tr = new TableRow(this);
        tr.setBackgroundColor(Color.WHITE);
        CheckBox cb = new CheckBox(this);
        tr.addView(cb);
        tableMaterialObra.addView(tr);
        LinearLayout myLayout = (LinearLayout) findViewById(R.id.my_layout);
        myLayout.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        startActivity(new Intent(RelativeLayoutTesting.this, com.sunil.MyListView.class));
    }

}
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
  • TableLayout and respectives TableRows are already on onCreate. And onResume method is not implemented (@Override) To call the new Intent: `Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, 0);` – Rodrigo Mathias Dec 28 '11 at 06:22
  • check whether you are doing anything in onActivityResult. i have tried the same exampe that i have given you for startActivityForResult. its working fine – Sunil Kumar Sahoo Dec 28 '11 at 06:54
  • `@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data.getExtras()!=null && data.getExtras().containsKey("data")) { Bitmap imagem = (Bitmap) data.getExtras().get("data"); //... TableLayout tl = (TableLayout) findViewById(R.id.tlFotos); LayoutInflater inflater = getLayoutInflater(); TableRow row = (TableRow) inflater.inflate(R.layout.foto_tablerow,null); ((CheckBox) row.getChildAt(0)).setTag(id); ((ImageView) row.getChildAt(1)).setImageBitmap(imagem); tl.addView(row); } }` Just it. – Rodrigo Mathias Dec 28 '11 at 11:03
  • The code above runs without any exception. Thanks for your time. – Rodrigo Mathias Dec 28 '11 at 11:05