綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 傳值給 FrameLayout 裡面的 activity [已解決]

[複製連結] 查看: 1584|回覆: 0|好評: 0
跳轉到指定樓層
樓主
f9999200 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2012-8-3 12:01

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
本帖最後由 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 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則