2013-01-24 68 views
0

我很困惑,請告訴我如何使用此選項卡主機傳遞參數。我想在第一個和第二個選項卡中傳遞參數。這裏是我的代碼:如何通過tab參數傳遞?

public class TabBarActivity_BalanceInquiry extends TabActivity { 
/** Called when the activity is first created. */ 
public static String varbalMessageType; 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main2); 
    setTabs() ;  
    varbalMessageType = getIntent().getExtras().getString("mno"); 
} 


private void setTabs(){ 

    addTab("payments", R.drawable.tab_home, AgAppAskPinForTransaction.class); 
    addTab("My Account", R.drawable.tab_home, AgAppMyAccountScreen.class);  
    addTab("Spend Analyzer", R.drawable.tab_home, AgAppPaymentScreen.class); 
    addTab("Notification", R.drawable.tab_home, AgAppPaymentScreen.class); 
    addTab("Help", R.drawable.tab_home, AgAppPaymentScreen.class); 
} 



private void addTab(String labelId, int drawableId, Class<?> c) 
{ 
    TabHost tabHost = getTabHost(); 

    Intent intent = new Intent(this, c); 
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator =  
    LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false); 
    TextView title = (TextView) tabIndicator.findViewById(R.id.title); 
    title.setText(labelId); 
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); 
    icon.setImageResource(drawableId); 

    spec.setIndicator(tabIndicator); 
    spec.setContent(intent); 
    tabHost.addTab(spec); 

    } 
} 

回答

1

標籤0

getParent().getIntent().putExtra("key", "value"); 

標籤1

String value = getParent().getIntent().getStringExtra("key"); 

你可以叫自己的標籤活動一樣,

Intent theIntent = new Intent(this, TabActivity.class); 
theIntent.putExtra("targetTab", 3); 
startActivity(theIntent); 

和傳遞數據或參數你可以創建單例Java類並傳遞你的數據到你想要的活動。

+0

沒有不在標籤間我想從其他活動像myactivity1.class傳遞到標籤活動1我是如何通過這樣的? –

+0

但我的代碼被稱爲只有1個活動,我爲其他4項活動做了什麼?我怎麼打電話?我上面的源代碼循環所有標籤文本名稱和繪製自動arnage所以我如何設置imaeg文本vew的eact選項卡?只是告訴我我的代碼修改哪部分?怎麼樣 –

+0

壞捷徑,用靜態變量? –