【问题标题】:Android: Fetch user inputs from one activity and display them on another activity [duplicate]Android:从一个活动中获取用户输入并将其显示在另一个活动中[重复]
【发布时间】:2017-08-18 07:17:46
【问题描述】:

我正在构建一个 android 应用程序,在该应用程序中,用户在 MainActivity 的几个 EditText 字段中输入他/她的详细信息,例如姓名、电话号码等。我应该获取所有这些数据,将它们传递给 SecondActivity 并将它们显示在 textViews 上。从 MainActivity 到第二个 Activity 的转换是通过 onclick 事件完成的。

编辑文本 xml

<EditText
     android:hint="@string/teacher_name_hint"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="10"
     android:id="@+id/teacher_name"
     android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,., "
     android:inputType="textPersonName"
     android:maxLength="42"
     android:maxLines="2"
     android:minLines="1"
     android:textColorHint="@color/abc_secondary_text_material_light" />

点击事件

public void roll_sheet_Activity(View v)
{
    Intent i = new Intent(MainActivity.this,Roll_sheet.class);
    startActivity(i);
}

【问题讨论】:

标签: java android xml


【解决方案1】:

使用意图传递数据

public void roll_sheet_Activity(View v)
{
Intent intent = new Intent(getBaseContext(), NextActivity.class);
intent.putExtra("stringName", stringName);
startActivity(intent);
}

关于下一个活动:

String s = getIntent().getStringExtra("stringName");

【讨论】:

    猜你喜欢
    • 2017-05-31
    • 2012-10-09
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    相关资源
    最近更新 更多