3

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

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.

Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
CoronaPintu
  • 1,865
  • 2
  • 17
  • 20

1 Answers1

3

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

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.

Communicative Between Fragments on Android

Community
  • 1
  • 1
Thalaivar
  • 23,282
  • 5
  • 60
  • 71
  • sorry i cannot understand about this GlobalApp class – CoronaPintu Jun 19 '13 at 13:15
  • @PintuCorna: Its a Singleton Pattern, http://en.wikipedia.org/wiki/Singleton_pattern – Thalaivar Jun 19 '13 at 13:16
  • ok but in my activity how can i get value from all edittext,, i had Basic fragment tab with two edittext, Taxes fragment tab with three edittext now in my this Acvitiy i want to store all edittext value in database so in my activity how can i get using this globalApp class. – CoronaPintu Jun 19 '13 at 13:19
  • You should use the GlobalApp.getInstance().Object for storing/getting values, you should send GlobalApp.getInstance().Object to your DB. you can use the GlobalApp.getInstance().Object then anywhere. – Thalaivar Jun 19 '13 at 13:23
  • but in my fragment had not any button so on editext how can i set value to this gloabalapp – CoronaPintu Jun 19 '13 at 13:42
  • You enter some value in EditText, how do you save it to DB. – Thalaivar Jun 19 '13 at 13:50
  • you can set the value to your GlobalApp Instance on Change of EditText Field. – Thalaivar Jun 19 '13 at 13:57
  • Thanks for this first i cannot understant this but when i impletement it and modify small change it work.. Thanks a lot – CoronaPintu Jun 20 '13 at 09:23