Android pass value to tab

In my Android application I would like to pass a value to a tab... I have a mainActivity then maintabactivity and three tab activities like tab1 tab2 and tab3.. I need to pass three different values to tab1 , tab2 , tab3.. I am able to pass the values... but when I pass values the result is not displaying in inside tab but as seperate pages.. I am giving my code below.. pls help..

MainActivity

    //Intent for tab operations

        //Personal Year tab operation
        Intent itab = new Intent(this, TabPersonalYr.class);
        //Personal Year Number
        itab.putExtra("name18",sum18 + "");
        startActivity(itab);

        //Personal Month tab operation
        Intent imonthtab = new Intent(this, TabPersonalMnth.class);
        //Personal Month Number
        imonthtab.putExtra("name19",sum19 + "");
        startActivity(imonthtab);

        //Personal Month tab operation
        Intent idaytab = new Intent(this, TabPersonalDay.class);
        //Personal Day Number
        idaytab.putExtra("name20",sum20 + "");
        startActivity(idaytab);*/

MainTabLayout Activity

  @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tablay_xm);

        TabHost tabHost = getTabHost();


        // Tab for PersonalYear
        TabSpec photospec = tabHost.newTabSpec("Personal Year");
        // setting Title and Icon for the Tab
        photospec.setIndicator("Personal Year", getResources().getDrawable(R.drawable.icon_photos_tab));
        Intent photosIntent = new Intent(this, TabPersonalYr.class);
       photospec.setContent(photosIntent);


        // Tab for Personal Month
        TabSpec songspec = tabHost.newTabSpec("Personal Month");        
        songspec.setIndicator("Personal Month", getResources().getDrawable(R.drawable.icon_songs_tab));
        Intent songsIntent = new Intent(this, TabPersonalMnth.class);
        songspec.setContent(songsIntent);

        // Tab for PersonalDay
        TabSpec videospec = tabHost.newTabSpec("Personal Day");
        videospec.setIndicator("Personal Day", getResources().getDrawable(R.drawable.icon_videos_tab));
        Intent videosIntent = new Intent(this, TabPersonalDay.class);
        videospec.setContent(videosIntent);

        // Adding all TabSpec to TabHost
        tabHost.addTab(photospec); // Adding photos tab
        tabHost.addTab(songspec); // Adding songs tab
        tabHost.addTab(videospec); // Adding videos tab

tab1Activity

TextView txt2 = (TextView) findViewById (R.id.textView14);
        txt2.setText(getIntent().getStringExtra("name18"));

Answers


You can use create singleton Class to pass value

public class ShareData{
    private volatile static ShareData shareData;
    public static ShareData data(){
    if(shareData == null){
        synchronized (ShareData.class) {
            if (shareData == null) {
                shareData = new ShareData();
            }
        }
    }
    return shareData;
    }  

    public String value;  
}

set value in Tab2

ShareData.data().value = "set in tab2";

get value in Tab1

txt2.setText(ShareData.data().value);

Need Your Help

EditorFor with Nullable<long> will trim fractions

c# asp.net asp.net-mvc

I have the following model class inside my asp.net mvc web application :-