0

I have successfully been able to send TextViews from Activity A using putExtra and send to Activity B into a TableRow. I can use SavePreferences with no problem to keep the view for next time. My problem is the next time I put some entries into Activity A and send to Activity B how do I create a new TableRow in Activity B that doesn't destroy the previously saved one?

After some Editing I now have it like this and it produces the TableRow from Activity A! Except I still cant SAVE the row or make a New One one.

TableLayout01 = (TableLayout) findViewById(R.id.TableLayout01);
    TableRow tableRow1 = new TableRow(this);

Intent in = getIntent();
    if (in.getCharSequenceExtra("blah") != null) {
        final TextView resultTextView = new TextView(this);
        resultTextView.setText(in.getCharSequenceExtra("blah"));
        tableRow1.addView(resultTextView);

Intent is = getIntent();
    if (is.getCharSequenceExtra("no") != null) {
        final TextView date = new TextView(this);
        date.setText(is.getCharSequenceExtra("no"));
        tableRow1.addView(date);



TableLayout01.addView(tableRow1, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,1.0f));
SmulianJulian
  • 801
  • 11
  • 33

2 Answers2

1

If you want to add a new tableRow, you first have to get a reference for your table layout. You can do that using the method findViewById.

TableLayout mainLayout = (TableLayout) findViewById(R.id.your_id);

Now, you should create a new tableRow based on the same layout which your already defined tableRow. To do that, you need inflate a layout. You will use the LayoutInflaterto create a new view based on your layout.

mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

newTableRow = LayoutInflater.from(getBaseContext()).inflate(R.layout.your_table_row, parent, false);//general use

To understand better what the layoutInflater do, read LayoutINflater Documentation.

At this point, you can set your textView inside you tableRow. Original author

final TextView = (TextView) newTableRow.findViewById(R.id.blahblah);
setmsg.setText(in.getCharSequenceExtra("blah"));  

After some manipulation you should add your tableRow inside your tableLayout.

tableLayout.addView(newTableRow)
Community
  • 1
  • 1
Bruno Mateus
  • 1,727
  • 18
  • 25
0

Just create the single instance of activity B by specifying in manifest file.

android:launchMode="singleInstance"

Create a static variable for the data to be inserted in table row. Use its getter and setter to set data from activity A and get data in activity B.

Droid 404
  • 11
  • 1