所有片段选项卡Android开值 [英] android get value from all fragment tab

查看:120
本文介绍了所有片段选项卡Android开值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不宣布framgmentActivity象下面这样:

i had declare framgmentActivity like below:

    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
    mTabHost.addTab(mTabHost.newTabSpec("basic").setIndicator("Basic",getResources().getDrawable(R.drawable.ic_launcher)),BasicProductFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("taxes").setIndicator("Taxes",getResources().getDrawable(R.drawable.ic_launcher)),TaxesProductFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("price").setIndicator("Price",getResources().getDrawable(R.drawable.ic_launcher)),PriceProductFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("stock").setIndicator("Stock",getResources().getDrawable(R.drawable.ic_launcher)),StockProductFragment.class, null);

现在所有frament我不得不宣布两三现在的EditText在这个活动中,我想从来自不同势frangment选项卡中所有的EditText获取数据。

Now in all frament i had declare two or three edittext now in this activity, i want to get data from that all edittext from diffrent frangment tab.

推荐答案

一个单独的类可以帮助您解决问题。

A singleton class could help solve your problem.

public class GlobalApp {
    private static GlobalApp instance = new GlobalApp();

    private GlobalApp() {}

    public static GlobalApp getInstance() {
        return instance;
    }

    public Details details = new Details ();

}

那么在这样的片段类中使用。

Then use in your Fragment class like this..

GlobalApp.getInstance().details.setSomeData("something");

现在,你可以得到所有这一切都在这些片段在mainActivity修改的数值

Now you can get all the values which are changed in those fragment in your mainActivity

 GlobalApp.getInstance().details.getSomeData();

我已经给了另外一个问题,其中有一些关于这相同的答案。

I have given the same answer for another question which has some relation to this.

<一个href="http://stackoverflow.com/questions/17040649/communicative-between-fragments-on-android/17041161#17041161">Communicative在Android

这篇关于所有片段选项卡Android开值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆