Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

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); T

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

=+ (b) If F is continuous, then E[F(X)) =;.

Answered: 1 week ago

Question

1. Understand how verbal and nonverbal communication differ.

Answered: 1 week ago