This week's book giveaway is in the Kotlin forum. We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line! See this thread for details.
Hello there,I'm new to Android ,i Want to change the Text in a fragment programatically .My problem is that I'm getting an error like this- Attempt to invoke virtual method 'int android.os.Bundle.getInt(java.lang.String)' on a null object reference
The first things that jumps out is that in line 30/31 of Tab_Activity you're creating a fragment which is then not used - so it will be be garbage-collected quickly. How are you actually using the fragment?
dev goku
Ranch Hand
Posts: 31
posted 1 year ago
I'm using this fragment in a Viewpager contained in a Tab Layout
dev goku
Ranch Hand
Posts: 31
posted 1 year ago
First I'm going to send a child position of an ExpandablelistView from an Activity to TabActivity,After setting up its Layout the TabActivity(Tablayout with 2 tabs and 2 fragmnets inside viewpager) gonna send the data it got to TipsFragment and it will populate the textview according to the childposition it got and actually i have 2 fragments i posted only one,please forgive me if I didn't give the right info you needed.
Tim Moores
Saloon Keeper
Posts: 5235
143
posted 1 year ago
I'm using this fragment in a Viewpager contained in a Tab Layout
OK, so there's more code in Tab_Activity which you didn't post? Well, it's hard to tell what's going on without seeing the relevant code bits.
The first thing to try is to call getArguments in the onCreate method rather than the onCreateView method. But that only makes sense if the fragment is actually being used (as opposed to just being created), and the code you posted doesn't show that part.
dev goku
Ranch Hand
Posts: 31
posted 1 year ago
Here's the full code on TabActivity,
and Thanks for Replying..
Tim Moores
Saloon Keeper
Posts: 5235
143
posted 1 year ago
1
It's as I suspected: the fragment to which you add the parameter in lines 45 to 48 is not used. Instead, you create another instance of the fragments in lines 61 and 62 to which you're not adding any parameters. Those are the ones that actually get used in the ViewPager.
Tim Moores
Saloon Keeper
Posts: 5235
143
posted 1 year ago
By the way, if you have exactly two views (or another small, fixed number of views) between which you want to switch, it would probably be easier to use a ViewFlipper rather than a ViewPager. No need to deal with fragments or adapters that way.
dev goku
Ranch Hand
Posts: 31
posted 1 year ago
Tim Moores wrote:It's as I suspected: the fragment to which you add the parameter in lines 45 to 48 is not used. Instead, you create another instance of the fragments in lines 61 and 62 to which you're not adding any parameters. Those are the ones that actually get used in the ViewPager.
How do i do that ?
dev goku
Ranch Hand
Posts: 31
posted 1 year ago
Tim Moores wrote:It's as I suspected: the fragment to which you add the parameter in lines 45 to 48 is not used. Instead, you create another instance of the fragments in lines 61 and 62 to which you're not adding any parameters. Those are the ones that actually get used in the ViewPager.
Ah.,It Worked Man as You said,I used the already created Fragment instance now.,It worked great.Thank you for your time..
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database