android从所有片段选项卡获取价值
作者:互联网
我已经声明了framgmentActivity,如下所示:
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,我想从不同的fragment选项卡中从所有edittext中获取数据.
解决方法:
单例课程可以帮助解决您的问题.
public class GlobalApp {
private static GlobalApp instance = new GlobalApp();
private GlobalApp() {}
public static GlobalApp getInstance() {
return instance;
}
public Details details = new Details ();
}
然后像这样在您的Fragment类中使用.
GlobalApp.getInstance().details.setSomeData("something");
现在,您可以在mainActivity中获取所有在这些片段中更改的值
GlobalApp.getInstance().details.getSomeData();
对于另一个与此相关的问题,我给出了相同的答案.
Communicative Between Fragments on Android
标签:android-fragments,android-fragmentactivity,android 来源: https://codeday.me/bug/20191123/2065360.html