Android get value from all fragment tab

I declared framgmentActivity as 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); 

Now in all frament I declared two or three edittexts now in this action, I want to get data from this entire edittext from the diff en frangment tab.

+4
source share
1 answer

The singleton class can 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 a Fragment like this in your class.

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

Now you can get all the values ​​that were changed in this fragment in your mainActivity

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

I gave the same answer to another question that has something to do with it.

Communication between fragments on Android

+4
source

Source: https://habr.com/ru/post/1487042/


All Articles