【问题标题】:Android Image View data?Android Image View 数据?
【发布时间】:2012-12-17 13:02:27
【问题描述】:

这里我有一个Activity,在XML 中创建ImageButton,在那个ImageButton 上排列两个ImageViews 和两个TextViews,像这样看点击这个ImageButton,数据在下一个@987654328 接收@。

我的问题是如何从这个Activity 获取所有ImageButton 数据到下一个Activity。任何有想法的人给出一些想法....

【问题讨论】:

  • 请解释清楚:在 ImageButton 上单击您想从两个 TextView 中收集数据,sip_namesip_status?

标签: android android-intent android-widget android-imageview


【解决方案1】:

点击按钮后,只需将要移动的数据放入其他活动中

public void onClick(View view) {
    Intent i = new Intent(this, ActivityTwo.class);
    i.putExtra("Value1", "This value one for ActivityTwo ");
    i.putExtra("Value2", "This value two ActivityTwo");
    // Set the request code to any code you like, you can identify the
    // callback via this code
    startActivityForResult(i, REQUEST_CODE);
  }

然后您可以像这样将这些数据放入其他活动中

Bundle extras = getIntent().getExtras();
    if (extras == null) {
      return;
    }
    String value1 = extras.getString("Value1");
    String value2 = extras.getString("Value2");

这称为显式意图。

【讨论】:

    【解决方案2】:

    您可以将所需的数据保存在Bundle 中并将其传递到Intent。如果您绝对需要传递Button,请尝试创建一个实现Serializable 的类,并在其参数中保存一个按钮实例,该实例被实例化为您的Button。并使用this 答案中的方法将这个Serializable 类通过Intent 传递给新的Activity

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2012-07-26
      相关资源
      最近更新 更多