-1

Hello Stackoverflow community, I looked at a lot of examples but I just can't apply it to my code. So I have the following code:

public class Profile extends AppCompatActivity {

private ViewPager mPager_profile;
private static final int NUM_PAGES = 3;
private PagerAdapter mPagerAdapter_profile;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.empty_profile_activity);

    // set up the slider
    mPager_profile = (ViewPager) findViewById(R.id.pager_profile);
    mPagerAdapter_profile = new ScreenSlidePagerAdapter_profile(getSupportFragmentManager());
    mPager_profile.setAdapter(mPagerAdapter_profile);
    // bottom dots
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout_profile);
    tabLayout.setupWithViewPager(mPager_profile, true);

    Intent intent = getIntent();
    String[] data = intent.getStringArrayExtra("data");

}

// some code here
...

private class ScreenSlidePagerAdapter_profile extends 
FragmentStatePagerAdapter {
    public ScreenSlidePagerAdapter_profile(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        switch (position){
            case 0:
                return new event_slide();
            case 1:
                return new profile_slide();
            case 2:
                return new option_slide();
            default:
                return null;

        }
    }

    @Override
    public int getCount() {
        return NUM_PAGES;
    }
}

}

and the following code is my event_slide.java fragment:

public class event_slide extends android.support.v4.app.Fragment{

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance){
        ViewGroup eventView = (ViewGroup)inflater.inflate(R.layout.login_event, container, false);

        return eventView;
    }
}

My question is: How can I pass the String array called "data" to my Fragment event_slide and than apply for example (String -->)data[0] to one of the TextView's, for example findViewById(R.id.textView9).setText(data[0]). I am new to android development, so please keep it simple.

Thanks in advance :)

j. albers
  • 3
  • 1

1 Answers1

0

The easiest way would be (but not the best):

public class EventSlide extends android.support.v4.app.Fragment{

    public String arg1;

    public EventSlide(String arg1){
        this.arg1 = arg1;
    }

    // Override OnCreate method, initialize your textView and set your text there
}

I recomend you take a look to newInstance pattern.

Damia Fuentes
  • 5,308
  • 6
  • 33
  • 65