我想获取在另一个活动中定义的文本视图的值?我正在使用安卓工作室。
您应该使用意向将值传递给另一个活动。 在第一个活动中:
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
intent.putExtra("YOURKEY", yourTextViewValue);
startActivity(intent);
访问下一个活动的意图
String textViewValue= getIntent().getStringExtra("YOURKEY");
第一个活动(具有 TextView(
SecondActivity.launchActivity(this, textView.getText().toString())
第二个活动(需要文本值(
public static void launchActivity(Context context, String textViewValue) {
Intent intent = new Intent(context, SecondActivity.class);
intent.putExtra("textValueKey", textViewValue)
context.startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
if (getIntent() != null) {
String textViewValue = getIntent().getStringExtra("textValueKey");
}
...
}