So kinda fresh on android but i have a problem. I got 2 Activities one where you click and get points in a TextView and the sum/value in the TextView get sent to the other Activity. In the second Activity i want to have a Button that gets visible if you have the exact or above value/sum in the TextView
Asked
Active
Viewed 45 times
-2
-
you just want and want you didn't even try this is not a code writing service – Mr. Patel May 19 '19 at 14:57
-
Please add a minimal, reproducible example (https://stackoverflow.com/help/reprex) of an exact problem that you are having. – jmsinusa May 19 '19 at 15:52
-
Mr.Patel... i have tried looking trough here and other sites to find some help on what i needed. but i was still stuck, sometimes you get stuck and need a point in the right direction.. – Niklas Eriksson May 21 '19 at 14:56
2 Answers
0
What you want is to pass the value from one activity to another. You can achieve this by using an intent to pass the value you want. Also, this question has already been made, you can find more details in the link:
How to pass value of one TextView to another TextView in different Activity
To make the button visible according to your needs,in the onCreate method from your second activity you can use:
if (value >= 50) {
button.setVisibility(View.VISIBLE)
} else {
button.setVisibility(View.GONE)
}

william xyz
- 710
- 5
- 19
-
The value I have passed, the thing I can't figure is how I will make a button visible by getting the value in the textview. As example if the Textview gets a value of 50 then it should be visible. Under 50 it should be invisible – Niklas Eriksson May 19 '19 at 14:55
-
0
For this do this code in Activity A:
Intent intent = new Intent(ActivityA.this,ActivityB.class);
intent.putExtra("sum","30");
startActivity(intent);
then do this in the second ActivityB:
if(getIntent().getExtras()!=null){
String sum = getIntent().getStringExtra("sun");
if(Integer.parse(sum)>number){
button.setVisibility(View.VISIBLE);
}else{
button.setVisibility(View.GONE);
}

Rajat Kumar Tyagi
- 116
- 5
-
-
Yeah sure and let me know buddy if it doesn't work then will try something else. – Rajat Kumar Tyagi May 19 '19 at 15:53