我使用 putExtra 从Activity A中发送TextViews,然后再发送到TableRow 中的Activity B里边。接下来我可以使用SavePreferences来保存view。现在的问题是我可以在Activity A中放入一些entries,然后发送到Activity B,如何在 Activity B中创建一个新的TableRow,还不毁坏之前保存的那个?
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));
你可以在活动B中按照以下步骤创建并保存一个新的TableRow:
例如:
Intent in = getIntent();
CharSequence data1 = in.getCharSequenceExtra("blah");
CharSequence data2 = in.getCharSequenceExtra("no");
TableLayout tableLayout = (TableLayout) findViewById(R.id.TableLayout01);
TableRow tableRow = new TableRow(this);
TextView textView1 = new TextView(this);
textView1.setText(data1);
tableRow.addView(textView1);
TextView textView2 = new TextView(this);
textView2.setText(data2);
tableRow.addView(textView2);
tableLayout.addView(tableRow, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f));
这样就可以在活动B中创建并添加新的TableRow,而不会毁坏之前保存的TableRow。