有一个计算器,当两个edittext框都被输入值后,点击“+”(button),然后点计算(button)跳到第二个activity并且输出值
那当我点+的时候可以把计算的值传到计算button里面吗然后再由计算button,setclass跳转到第二个activity获取计算button里面的值?

解决方案 »

  1.   

    可以的。反正就是Activity之间的跳转问题,跟你传的值没关系。不管你是先计算好传过去得到的结果,还是传过去两个值,到另外一个Activity中计算,都一样...
      

  2.   

    主要是传值的问题,intent的主要用途是发送广播、动作之类的,在创建该对象的时候把自己需要传递的值传到下一个intent就行了。如果说是两个activity的话,比如activity A 和 activity B,当你从 A 跳到 B 的时候,不要将 A finish掉,在 A 里面需要有onActivityResult 这个方法,从 A 跳到 B 的时候使用 startActivityForResult 这个方法就行了,具体怎么使用楼主去查一下api
      

  3.   

    可以的,传递的数据都放到intent中就好了
      

  4.   

    public class Activity01 extends Activity {
    private static final String TAG="Activity01";
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Log.v(TAG,"onCreate");
            
            Button button_next=(Button)findViewById(R.id.next);
            button_next.setOnClickListener(new Button.OnClickListener(){
             public void onClick(View v){
             Intent intent=new Intent();
             intent.setClass(Activity01.this, Activity02.class);
             startActivity(intent);
             Activity01.this.finish();
             }
            });
            
            Button button_exit=(Button)findViewById(R.id.exit);
            button_exit.setOnClickListener(new Button.OnClickListener(){
             public void onClick(View v){
             Activity01.this.finish();
             }
            });
        }
    public class Activity02 extends Activity {
    //private static final String TAG="Activity01";
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity02);
            //Log.v(TAG,"onCreate");
            
            Button button_before=(Button)findViewById(R.id.before);
            button_before.setOnClickListener(new Button.OnClickListener(){
             public void onClick(View v){
             Intent intent=new Intent();
             intent.setClass(Activity02.this, Activity01.class);
             startActivity(intent);
             Activity02.this.finish();
             }
            });
        }
    }<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="这是第二个Activity。"
        />
    <Button android:id="@+id/before"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Activity01"
      /></LinearLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
    <Button android:id="@+id/next"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Activity02"
      />
    <Button android:id="@+id/exit"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Exit"
      /></LinearLayout>复制,粘贴,导入需要的包,就可以了。你感受下。