last day (16 days later) » 

10:34 PM
0
A: Call method in fragment

Xaver KapellerRegarding your questions: 1) There is a lifecycle method called onViewCreated() which is executed after the method onCreateView() has finished. You can overwrite it like this and use it to execute checkRow(): @Override public void onViewCreated(View view, Bundle savedInstanceState) { supe...

 
Hi thank you... i want passing array's from MainActivity to fragment arrivi. i need to bundle.putStringArray(arrivi.EXTRA_DATA_A, dataA)... from MainActivity?
 
Yes you do it like I demonstrated in my answer.
 
yes... look here: - arrivi.java updated: paste.ubuntu.com/7313378 and in MainActivity: paste.ubuntu.com/7313386 it's work but doesn't execute OnViewCreated() in arrivi fragment
 
I'm sure that it doesn't work, you are never using the instance created by newInstance() in your code. You have to place the Fragment somewhere using a FragmentTransaction. Also the newInstance() method belongs into the arrivi class. And please edit code into your questions don't link to it.
 
Ok, i have added FragmentTransiction but i have a problem... i have edited 1st post... Thank you
 
10:34 PM
I edited my answer accordingly.
 
You are the best!!! but i have problem... i have edited 1st post
 
Well I can't tell what's wrong just from a screenshot, the code itself seems fine. Try to save the files or restart Eclipse, a clean & rebuild could also help. You can also look at the error message by going to Window -> Show View -> Problems.
 
I have restarted eclipse... but i get the error... i have edited 1st post
I have removed @Override... but the error is fragment_container fragment_container cannot be resolved or is not a field.. why?
 
Well do you have a view with the id R.id.fragment_container in your layout somewhere? And if yes you can also check the imports. Maybe you are importing the wrong R. If there is a line like import android.R; at the top of the file you need to remove it and import the correct R.
Please don't forget to accept my answer if it helped you. This indicate top other people that this answer was helpful to you and we both get a little reputation from it.
 
;) ;) yes dob't worry :) Hi.. i haven't fragment_container... i have arrivi.xml layout_main.xml.... how to replace fragment_container?
 
10:34 PM
Please edit your layout_main.xml into your question and I can show you.
 
Ok :) i have added layout_main.xml and arrivi.xml
 
Where do you want the arrivi Fragment to go? Do you want to display it in your ViewPager or do you just want to add it to your layout?
 
In ViewPager Tab, but the problem is fragment_container for me doesn't exist. Thank you!
 
If you want to display it in the ViewPager you don't do it with FragmentTransactions. Those are only used to add a Fragment to an existing layout. What you need to do is implement a PagerAdapter in your case most likely a FragmentStatePagerAdapter add assign the Adapter to your ViewPager. I will edit my answer accordingly, but give me a few minutes to do it.
 
you said: I'm sure That it does not work, You have to place the Fragment somewhere using a FragmentTransaction. I want to do this
 
10:34 PM
Well if you want it to be displayed in the ViewPager than you have to implement a PagerAdapter. When I said that earlier I thought you wanted to place the Fragment somewhere inside your layout, I didn't know you wanted it in a ViewPager. You have to decide what you want to do, I can show you how to do either of them.
 
This is my app: imagebin.org/307101 - imagebin.org/307102 i want arrivi.xml into Tab arrivi.. my problem is bundle is null ...i have tabepageAdapter. EDIT: i have added pagetabadapter in 1st post
 
What do you mean the problem is that the Bundle is null? The TabPagerAdapter is ok, but you should use the newInstance() method of the arrivi Fragment there too. You can pass values to the TabPagerAdapter through the constructor. Or if you nest the TabPagerAdapter in the MainActivity without the static keyword than you can access member variables of the MainActivity in the TabPagerAdapter.
 
in MainActivity there are 12 arrays,and I wish that arrays of mainactivity also exist on arrivals for use of CheckRow(). I have moved newIstance in Arrivi class, but bundle is null... i have edited 1st post! Thank you!
 
I will edit a solution into my answer. Give me a few more minutes.
I edited my answer accordingly.
 
Hi thank you so much... but.. there isn't a problem... i get this error in switch/case: Cannot use this in a static context. I have edited 1st post --- UPDATED2 ARRIVI.JAVA ---- Can you help me with example please? Thank you +++++
 
10:34 PM
Why don't you use a Bundle to pass the String[] to the Fragment? You can fix the error you are getting by using a Bundle to pass the data to the Fragment like I described in my answer.
 
Ok, but if i use the bundle, i need to fragmentTransiction?
 
No that has nothing to do with each other.
 
i have edited 1st post... look at @ -----RE-EDITED-------- i get a NullPointer bundle
 
What the hell are you doing? That's all wrong, just look at my answer, you have to it like I suggested. I will again edit a solution for this my answer.
 
I have edited 1st post... Newistance in println is null... look MainActivity and arrivi.java in -------RE EDITED------
 
10:34 PM
I have updated my answer.
 
I have tried your code.... but A_Compagnia[1] etc... are null...
 
Well I tested the code I edited into my answer. It's working perfectly for me. You must have gotten something wrong.
You are getting null there because you never set any value to A_Compagnia[1]. I just think you have know idea what you are doing... That you have such big problems basically just copy & pasting my answer. You know you should know how to program before trying to write an app.
 
Hi sorry
i have edited 1st post
i wrong in mainActivity
the problem is into mainactivity...
The strings are in SplashScreen.java, i have populated strings into asynctask into splashscreen.java, when asynctask finished call getValue(...) and pass the strings in mainActivity
 
10:54 PM
This is your problem: MainActivity m = new MainActivity();. What do you want to do their? You should never ever instance an Activity. Why is this still your code anyway? I already told you about that in my answer.
 
public void onTaskFinished() {

MainActivity m = new MainActivity();
m.GetValue(A_Compagnia,A_CodiceVolo,A_Citta,A_OraPrevista,A_OraStimata,A_StatoVolo,
P_Compagnia,P_CodiceVolo,P_Citta,P_OraPrevista,P_OraStimata,P_StatoVolo);
}
this is into SplashScreen class ... and GetValue is into MainActivity
 
What do you expect this code to do? I don't even understand with your explanation. It's completely wrong.
 
this is a splashscreen for my app: paste.ubuntu.com/7318263
and this is mainActivity: paste.ubuntu.com/7318269
I want pass strings[] from Splashscreen > to mainactivity... and from mainactivity to arrivi
I have to use bundle in mainactivity?
 
11:11 PM
Omg there are so many things wrong with this code... But you seem to have a perfect use case for implementing a Singleton to manage your data. Doing this like you want to do way more complicated that it has to be... Anyway I don't understand why I still see this in your code: MainActivity m = new MainActivity();. It's completely wrong. You can delete this whole block of code.
 
in splashscreen.java?
if i delete MainActivity m = new MainActivity() how call GetValue into MainActivity from SplashScreen.java?
if i delete MainActivity m = new MainActivity() i get this error:
The method GetValue(String[], String[], String[], String[], String[], String[], String[], String[], String[], String[], String[], String[]) is undefined for the type SplashScreen
when asynctask finish, i want pass Strings[] in mainactivity for use them in
public Fragment getItem(int i) {
switch (i) {
case 0:
return new info();
case 1:
return Arrivi.newInstance(A, A_Compagnia, A_CodiceVolo, A_Citta, A_OraPrevista, A_OraStimata, A_StatoVolo);
case 2:
 
Yeah I understand that, but the code is badly designed, it's really a mess. I'm going to fix it, I will edit my answer in a few minutes.
 
genius can help me? :)
 
11:32 PM
I have edited the code into my answer. I tested it and it works. Now please get it to work, I can't believe I'm still helping you....
 
11:47 PM
works but only this context cannot be resolved
in mainactivity
 
I edited my answer and corrected the mistake in the MainActivity.
 
I do not know how to thank you ... you have been very kind
:D
while(1) System.out.println("THANK YOU");
 

  last day (16 days later) »