我有两个类文件。它创建一个值并将其存储在字符串 (PINString) 中。 第二个类文件使用变量在 TextView 中显示。如下所示: 目前变量 PINString 的值没有被传递
第一
{
//
int randomPIN = (int)(Math.random()*9000)+1000;
//
String PINString = String.valueOf(randomPIN);
Intent i = new Intent(getBaseContext(),verification.class);
i.putExtra("PINString", PINString);//transfer string
startActivity(i);
}
第二
public void onClick(View view)
{
String PINString;
Bundle bundle = getIntent().getExtras();
PINString = bundle.getString("SMSDemo.PINString");
TextView textView2 = (TextView) findViewById(R.id.textView2);
textView2.setText(PINString);
最佳答案
您将变量作为“PinString”传递:
i.putExtra("PINString", PINString);//transfer string
所以,而不是这个:
PINString = bundle.getString("SMSDemo.PINString");
使用
PINString = bundle.getString("PINString");
关于java - 跨不同类使用 A 变量。安卓系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22257235/