I have an app that builds a bundle and passes it to a second activity, for the data within the bundle to be used later.
So far I just want to display one of the elements in the bundle in a TextView
, to be sure that I can handle the data in activity two. I'm calling getView().findViewByID(R.id.theTextViewIWant)
, but it is always returning null
, and the IDE says it cannot resolve getView()
. I believe it has got to be something I don't fully understand about the View
that holds the second activity, so I'd appreciate any help.
public class MyClass extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mark_student);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
@Override
protected void onStart(){
super.onStart();
Bundle receivedInfo = getIntent().getExtras();
String unitSelected = receivedInfo.getString("key");
TextView textViewBox = (TextView) getView().findViewById(R.id.textView2);
textViewBox.setText(unitSelected);
}
I've tried these two other ways of getting the view object, and they haven't worked either:
ViewGroup rootView = (ViewGroup) ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0); //nope
View fragmentView = getView(); //neither