简体   繁体   English

如何将值从TabActivity发送到Activity?

[英]how to send the values from TabActivity to Activity?

In my TabActivity , i'm sending value to other Activity how to do that 在我的TabActivity中,我正在向其他Activity发送价值如何做到这一点

in this TabActivity how can i send the bundle to other Activity plz tell me how to pass the value to my other ReceivedList Activity plz tell me .... 在这个TabActivity中如何将包发送到其他Activity plz告诉我如何将值传递给我的其他ReceivedList Activity请告诉我....

    public class TabViewForSendAndRecv extends TabActivity{

private TabActivity tabhost1;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabviewforsendandrecv);


    Bundle bundle = getIntent().getExtras();
    String stuff = bundle.getString("number"); 



         final TabHost tabHost = getTabHost(); 



      TextView txtTab = new TextView(this);
        txtTab.setText("Received Alerts");
        txtTab.setPadding(8, 9, 8, 9);
        txtTab.setTextColor(Color.WHITE);
        txtTab.setTextSize(14);
        //txtTab.setTypeface(localTypeface1);
        txtTab.setGravity(Gravity.CENTER_HORIZONTAL |                                            Gravity.CENTER_VERTICAL);


        TabHost.TabSpec spec;

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("Tab1").setIndicator(txtTab).
        setContent(new Intent(this, ReceivedList.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));


        tabHost.addTab(spec);




      //tab 2


        TextView txtTab1 = new TextView(this);
        txtTab1.setText("Sent Alerts");
        txtTab1.setPadding(8, 9, 8, 9);
        txtTab1.setTextColor(Color.WHITE);
        txtTab1.setTextSize(14);
        //txtTab.setTypeface(localTypeface1);
        txtTab1.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);


        TabHost.TabSpec spec1;
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec1 = tabHost.newTabSpec("Tab2").setIndicator(txtTab1).setContent(new Intent(this, SentList.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));



        tabHost.addTab(spec1);

You can pass this data like this: 您可以像这样传递这些数据:

edit this line: 编辑此行:

setContent(new Intent(this, ReceivedList.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) setContent(new Intent(this,ReceivedList.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))

To: 至:

Intent receivedListIntent = new Intent(this,ReceivedList.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

receivedListIntent.putExtra("number", stuff);

setContent(receivedListIntent);

And you can get this data in ReceivedList Activity: 您可以在ReceivedList活动中获取此数据:

Bundle bundle = getIntent().getExtras();
String stuff = bundle.getString("number");

There is still a way to exchange data between multiple Activities. 仍有一种方法可以在多个活动之间交换数据。 To do this you need to create a class application class. 为此,您需要创建一个类应用程序类。 And create your public field to your data. 并为您的数据创建公共字段。 And you can set or get this field in all Activities. 您可以在所有活动中设置或获取此字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM