hcg_21 2013-08-05 06:07 采纳率: 0%
浏览 991

根据其它的activity中的值如何创建和保存一个新的tableRow?

我使用 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));
  • 写回答

1条回答

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-01-09 20:53
    关注

    你可以在活动B中按照以下步骤创建并保存一个新的TableRow:

    • 从Intent中接收数据,并将它们转换为适当的类型(例如CharSequence)。
    • 使用这些数据来创建新的TextViews。
    • 将新创建的TextViews添加到新的TableRow中。
    • 将新的TableRow添加到TableLayout中。

    例如:

    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。

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题