Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将值从TabActivity发送到Activity?_Android_Android Tabhost - Fatal编程技术网

Android 如何将值从TabActivity发送到Activity?

Android 如何将值从TabActivity发送到Activity?,android,android-tabhost,Android,Android Tabhost,在我的TabActivity中,我向其他活动发送值,如何做到这一点 在本活动中,我如何将捆绑包发送到其他活动请告诉我 如何将值传递给我的其他ReceivedList活动请告诉我 public class TabViewForSendAndRecv extends TabActivity{ private TabActivity tabhost1; public void onCreate(Bundle savedInstanceState) { super.onCreate(

在我的TabActivity中,我向其他活动发送值,如何做到这一点

在本活动中,我如何将捆绑包发送到其他活动请告诉我 如何将值传递给我的其他ReceivedList活动请告诉我

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

您可以按如下方式传递此数据:

编辑此行:

setContent(新的意图(这个,ReceivedList.class)。addFlags(意图.FLAG\u活动\u清除\u顶部))

至:

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

receivedListIntent.putExtra("number", stuff);

setContent(receivedListIntent);
您可以在ReceivedList活动中获取此数据:

Bundle bundle = getIntent().getExtras();
String stuff = bundle.getString("number");
仍然有一种方法可以在多个活动之间交换数据。为此,您需要创建一个类应用程序类。并为数据创建公共字段。您可以在所有活动中设置或获取此字段