我是 Android Studio 和 java 的新手,所以希望你能帮助我。我想将一个双变量从 on 活动传递到下一个。但我不确定需要什么,所以在接收活动中输入 defaultValue。这是活动一的代码:@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button weiter = (Button)findViewById(R.id.weiter); weiter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText EingabeBreite = (EditText)findViewById(R.id.breite); double breite = Double.parseDouble(EingabeBreite.getText().toString()); Intent rüber = new Intent(getApplicationContext(), Main2Activity.class); getIntent().putExtra("next", breite); startActivity(rüber);这是第二个活动的代码:@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); TextView ergebnis = (TextView)findViewById(R.id.textView2); Bundle extras = getIntent().getExtras(); double breite = extras.getDouble("next"); ergebnis.setText(Double.toString(breite));
3 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
使用此代码:
Intent mIntent = new Intent(HomeActivity.this, CenterActivity.class);
mIntent.putExtra("thevalue ", 0.0d);
startActivity(mIntent);
Intent intent = getIntent();
double d = Double.parseDouble(intent.getExtras().getString("thevalue "));
添加回答
举报
0/150
提交
取消