0

このタブ ホストでパラメーターを渡す方法を教えてください。最初と 2 番目のタブでパラメーターを渡したいです。これが私のコードです:

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);

  }
}
4

1 に答える 1

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クラスを作成し、必要なアクティビティにデータを渡すことができます。

于 2013-01-24T07:13:25.157 に答える