1

我要上第一个Activity(在layout里写)你叫什么名字?!当一个人在电影中写下他的名字时,它应该出现 Hello(THE NAME)!我该怎么做?

4

2 回答 2

3

这就是您使用参数调用意图的方式

Intent search = new Intent(FirstActivity.this, SecondActivity.class);
search.putExtra("param_a", content1);
startActivity(search);
于 2013-05-14T13:36:07.753 回答
2
public class MainActivity extends Activity {
     @Override
    public void onCreate(Bundle savedInstanceState) {
          //some stuff

          //Note : start the activity from an event (onClick per example)
          String stringObject = "Foo"; //or a String you get from your editText
          Intent i = new Intent(MainActivity.this, OtherActivity.class);
           i.putExtra("name", stringObject);
           startActivity(i);
     }
}



public class OtherActivity extends Activity {
         @Override
        public void onCreate(Bundle savedInstanceState) {
              //some stuff

               Bundle extras = getIntent().getExtras(); 
               String name = "";

               if (extras != null){
                name = extras.getString("name");
                myTextView.setText(name);
              }

         }
    }
于 2013-05-14T13:40:46.943 回答