close

對你的專案右鍵→New→Activity→Empty Activity ::建立一個新的Activity

MainActivity.java:

 Intent intent = new Intent();                                           //郵局
 intent.setClass(MainActivity.this,NetActivity.class);       //指到的頁面
 Bundle bundle = new Bundle();                                     //放值宣告

//把抓到的東西使用這名稱指定
bundle.putString("username",((EditText)findViewById(R.id.username)).getText().toString());                
bundle.putString("Spinner",((Spinner)findViewById(R.id.spinner)).getSelectedItem().toString());
intent.putExtras(bundle);
startActivity(intent);               //打這個才會動作


NetActivity.java:

//EditText
name = (EditText)findViewById(R.id.name);
Bundle usename = this.getIntent().getExtras();
Bundle namec = this.getIntent().getExtras();
//將取得的Bundle資料設定
String result = usename.getString("username");
String resultA = namec.getString("Spinner");
//顯示結果
name.setText("你的帳號是:" + result + "你的工作單位是:" + resultA);

arrow
arrow
    全站熱搜

    淺翔 發表在 痞客邦 留言(0) 人氣()