Android 台灣中文網

標題: 傳值給 FrameLayout 裡面的 activity [已解決] [打印本頁]

作者: f9999200    時間: 2012-8-3 12:01
標題: 傳值給 FrameLayout 裡面的 activity [已解決]
本帖最後由 f9999200 於 2012-8-3 12:53 編輯

1. 我的第一頁是 由spinner選擇之後,再傳值進去到別頁

2. spinner選擇之後的頁面是 由 TAB 跟 FrameLayout 所結合的頁面

3. TAB 有 三個activity(都是FrameLayout) 分別是  "地圖"   "資訊"  "交通"

當我從第一頁的spinner選擇之後,會傳不同的值給這三個activity,

如果當我選擇之後,個別啟動這三個ACTIVITY 是可以成功的

但是,跳到TAB 頁面 就會發生錯誤,是不是哪裡有錯誤呢?

請各位大大救救我吧~~


這是spinner傳值的代碼:

  1.                 intent.setClass(taipeicity.this, market.class);
  2.                         intent2.setClass(taipeicity.this, market_info.class);
  3.                         intent3.setClass(taipeicity.this, market_map.class);

  4.                         //傳遞資料給Activity-------------
  5.                         bundle.putString("strCnametxt", Cnametxt);
  6.                         bundle.putString("strEnametxt", Enametxt);
  7.                         bundle.putString("strTimetxt", Timetxt);
  8.                         bundle.putString("strIfotxt", Ifotxt);
  9.                         bundle.putString("strAddresstxt", Addresstxt);
  10.                         bundle.putString("srtPictxt", Pictxt);

  11.                         intent2.putExtras(bundle);
  12.                         intent3.putExtras(bundle);

  13.                         startActivity(intent);
複製代碼
這個是,TAB的代碼:

  1. //TAB按鈕
  2.         Resources res = getResources(); // Resource object to get Drawables  
  3.         TabHost tabHost = getTabHost();  // The activity TabHost  
  4.         TabHost.TabSpec spec;  // Resusable TabSpec for each tab  
  5.         Intent intent; // Reusable Intent for each tab
  6.         
  7.         
  8.         //地圖
  9.         intent = new Intent().setClass(this, market_map.class);  
  10.         spec = tabHost.newTabSpec("map").setIndicator("",  
  11.                           res.getDrawable(R.drawable.ic_map))  
  12.                       .setContent(intent);  
  13.         tabHost.addTab(spec);  

  14.         //資訊
  15.         intent = new Intent().setClass(this, info.class);  
  16.         spec = tabHost.newTabSpec("albums").setIndicator("",  
  17.                           res.getDrawable(R.drawable.ic_v_inf))  
  18.                       .setContent(intent);  
  19.         tabHost.addTab(spec);  
  20.         
  21.         //交通
  22.         intent = new Intent().setClass(this, traffic.class);  
  23.         spec = tabHost.newTabSpec("songs").setIndicator("",  
  24.                           res.getDrawable(R.drawable.ic_t_inf))  
  25.                       .setContent(intent);  
  26.         tabHost.addTab(spec);  
  27.                        
  28.         tabHost.setCurrentTab(0);
複製代碼
這是,"資訊"接受傳值的代碼:
  1. //             接受SpinnerBundle傳來的值  
  2.         Bundle bundle=this.getIntent().getExtras();     

  3.      String StrEnametxt=bundle.getString("strEnametxt");
  4.      String StrTimetxt=bundle.getString("strTimetxt");
  5.      String StrIfotxt=bundle.getString("strIfotxt");
  6.      String StrAddresstxt=bundle.getString("strAddresstxt");
  7.      
  8.   
  9.    
  10.      TextView Enametxt=(TextView) findViewById(R.id.Enametxt);
  11.      TextView Timetxt=(TextView) findViewById(R.id.Timetxt);
  12.      TextView Ifotxt=(TextView) findViewById(R.id.Ifotxt);
  13.      TextView Addresstxt=(TextView) findViewById(R.id.Addresstxt);
  14.      
  15.    
  16.      Enametxt.setText(StrEnametxt);
  17.      Timetxt.setText(StrTimetxt);
  18.      Ifotxt.setText(StrIfotxt);
  19.      Addresstxt.setText(StrAddresstxt);
  20.          
複製代碼
==========================================================


解決的方法:

先在  spinner選擇之後的頁面  先做一個 Bundle的接收

然後  同一個頁面 寫 Bundle2 傳送

最後再 "資訊" 的 ACTIVITY   接收 Bundle2 的資訊




不知道這樣解決的方法合不合理......這是我剛剛突然想到的




歡迎光臨 Android 台灣中文網 (https://apk.tw/) Powered by Discuz! X3.1