Author | Message |
---|---|
lbriggs
Posts: 57
|
Posted 12:08 Apr 27, 2014 |
So by default eclipse sets up fragments when creating a new activity. How do you access Views inside a fragment in the activities onCreate() method? Every time I attempt: ImageView image = (ImageView) findViewById(R.id.image); I get a null value. It seems like the Activity cannot access the fragments UI widgets. This wasnt a problem before when I wasnt using Fragments, but since thats the preffered way of doing it, I am confused. Loran |
msargent
Posts: 519
|
Posted 12:21 Apr 27, 2014 |
You should do your ui setup for the fragment in the fragment's onCreateView() method. That will get called when onCreate() gets called in the parent activity. But if you are trying to have a sliding transitions between fragments, you might consider this post: http://stackoverflow.com/a/9856449/399741 Last edited by msargent at
12:21 Apr 27, 2014.
|
lbriggs
Posts: 57
|
Posted 12:27 Apr 27, 2014 |
Redid the app, in 5 mins using Android Studio without the use of Fragments and it worked. |
lbriggs
Posts: 57
|
Posted 12:29 Apr 27, 2014 |
So you want to create another class to handle the lifecycle of the fragment to do that? |
msargent
Posts: 519
|
Posted 12:31 Apr 27, 2014 |
For each fragment, you would make a class for it, and override its callback methods like you would with an activity (with some small differences). |
lbriggs
Posts: 57
|
Posted 12:39 Apr 27, 2014 |
thank you |