0

我正在尝试通过温度转换生成一个有效的值,然后将此值传输到另一个活动中的空白文本框中,但代码似乎不起作用。这是两部分 - 它来自的一个和它需要去的一个......

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();
            }


          });
      }}
4

1 回答 1

4

一行中有一个错字:

nameView.setText(getIntent().getExtras().getString("Value"));

更改Valuevalue

于 2013-04-22T20:04:18.757 回答