button1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
numberPicker1int = Integer.parseInt(numberPicker1.getContext().toString());
numberPicker2int = Integer.parseInt(numberPicker2.getContext().toString());
value1=numberPicker1int;
value2=numberPicker2int;
}
});
value1 和 value2 在其他 Activity (MainActivity)中。我如何获取 value1(int) 和 value2(int)?
最佳答案
在主要 Activity 中:
Intent Intent = new Intent(MainActivity.this, SecondActivity.class);
Intent.putExtra("值1",值1);
Intent.putExtra("值2",值2);
startActivity( Intent );
在您想要访问值的辅助 Activity 中:
Bundle bundle = getIntent().getExtras();
int value1 = bundle.getInt("value1");
int value2 = bundle.getInt("value2");
关于java - 从其他 Activity 获取整数变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26829977/