Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with my android studio app. When a button is clicked a textView changes to You Clicked the button! There is a second
I need help with my android studio app. When a button is clicked a textView changes to You Clicked the button! There is a second button that when clicked opens a second activity with another TextView. The app is supposed to pass the text of the first TextView to the one in the second activity, but I cant figure this out without crashing my code. How do I pass data from one cavity to the other?
patActivity aimed as to be public class MainActivity extends AppCompatActivity { TextView tv; //declaring a TextView variable named as tv Button button, b2; //declaring a Button variable named as btn @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv=findViewById(R.id.tv); button=findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { tv.setText("You have clicked the button"); }); b2 = findViewById(R.id.button2); b2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openActivity2(); public void openActivity2() { Intent intent = new Intent( packageContext: this, MainActivity.class); startActivity (intent); @Override public void onSaveInstanceState(@NonNull Bundle outState, NonNull PersistableBundle outPersistentState) { super.onSaveInstanceState(outState, out PersistentState); outState.putString("key", tv.getText().toString(); public class Main Activity extends AppCompatActivity { TextView tv2; String string; 14 of @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); Intent intent = getIntent(); tv2=findViewById(R.id.textView2); string = savedInstanceState.getString(key: "key"); tv2.setText(string);Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started