我正在尝试使用温度转换生成一个有效的值,然后将此值转移到另一个活动的空白文本框中,但代码似乎不起作用。以下是两个部分 - 它来自的部分以及需要进入的部分......
public class MainActivity extends Activity {
private EditText text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (EditText)findViewById(R.id.MainActivityText);
final EditText et = (EditText) findViewById(R.id.MainActivityText);
Button b = (Button) findViewById(R.id.Button01);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), SecondScreen.class);
startActivityForResult(myIntent, 0);
Intent intent=new Intent(MainActivity.this, SecondScreen.class);
intent.putExtra("value", et.getText().toString());
startActivity(intent);
}
});
}
@SuppressLint("NewApi")
public class SecondScreen extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondscreen);
TextView nameView=(TextView) findViewById(R.id.SecondScreenText);
nameView.setText(getIntent().getExtras().getString("Value"));
Button next = (Button) findViewById(R.id.Button02);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
}}
答案 0 :(得分:4)
有一个拼写错误:
nameView.setText(getIntent().getExtras().getString("Value"));
将Value
更改为value