How to exchange the value of variables between Activitys?

Asked

Viewed 81 times

0

I have three classes :

Main1
Main2
Main3

Now inside the Main1 have a float:

static float f = 3.5;

And inside the Main2 have a TextView:

public static TextView tv;

And in the Main3 want to put :

  Main2.tv. setText("O valor do float f é " + Main1.f);

I tried to use the codes that were presented to me in the "duplicate", but none clarified me, nor did it help to solve my problems. And the answers they gave me I do not know why they were not working, because I am doubtful on this part, and what they passed me, exchanged information between classes of the same Activity.

  • I answered, but just as you’ve got it works.

  • What is the difference between this and this: http://answall.com/questions/35336/como-trocar-informa%C3%A7%C3%B5es-entre-classes?

  • No @bigown, it’s to close...

  • It’s because everything I had on that couldn’t solve my problem ...

  • And now I’ve added the float

  • Guti but what problem do you have in particular?

  • 1

    @Gutie In theory, the answers to your previous question answer this as well. If it is not working, please [Dit] this question explaining better what is going wrong. The edit you made in the other question invalidated the answers that already existed (including one that was accepted), so we intend to reverse it soon. For more details, join discussion of the case in Meta.

  • @bfavaretto I tried to use the codes they passed me in the duplicate however, passed me only of classes, and I want of Activitys(screens) ...

  • @Gutie seems to me that you still don’t understand what we want... To help you, we would need you to explain the why of the previous solution does not solve your problem... When you try, is accused some error? It has how to put the part of the code that is giving problem?

  • 1

    @Gutie on Android the way to pass between Ativity’s is the one that answered you in duplicate. Or by reference with the static or by Intent with the putExtra. If you have a specific error that appears to you edit this question and put it there

  • @Gammeth the problem is here... Main2.tv. setText("O valor do float f é " + Main1.f);

  • And so far I don’t know why..

  • @Gutie He doesn’t print any kind of mistake for you??

  • 10-14 17:52:41.031: E/AndroidRuntime(2779): FATAL EXCEPTION: main
10-14 17:52:41.031: E/AndroidRuntime(2779): java.lang.NullPointerException
10-14 17:52:41.031: E/AndroidRuntime(2779): at com.gustavo.sample.Count$2.onClick(Count.java:39)
10-14 17:52:41.031: E/AndroidRuntime(2779): at android.view.View.performClick(View.java:4204)
10-14 17:52:41.031: E/AndroidRuntime(2779): at android.view.View$PerformClick.run(View.java:17355)
10-14 17:52:41.031: E/AndroidRuntime(2779): at android.os.Handler.handleCallback(Handler.java:725) @Gammeth

  • Here is my code for those who want to look: https://github.com/AndroidComunite/Android-Error/tree/master

  • 1

    @Gutie the idea of putting the error in the question, is editing her and putting in her this data... Also, no one will debug for you your entire project... One idea of what you can do is try to go debugging slowly... Try to store in temporary variables of type: float fl = Main1.f; TextView text = Main2.tv; and see if they’ve really been initialized...

  • Blz I’ll try to debug part by part,

  • @Gammeth I debugged and the mistake is when I try to put something like: Main3.text.setText("Valor " + MainActivity.fl);

Show 13 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.