A
A
Anire19852013-12-24 11:38:15
Android
Anire1985, 2013-12-24 11:38:15

How to implement text change when switching to another activity?

There is:
an activity with two buttons (btn_1; btn_2) and a second activity with a TextView.
String resource

<string name="tx_1">Hello</string>
<string name="tx_2">Android</string>

It is necessary that when you click on a certain button (btn_1), the second activity opens and the text in the TextView changes. (according to the string resource);
For example, I clicked on the btn_2 button, the second activity opened and the text changed to "Android".
How to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
localhostEU, 2013-12-25
@Anire1985

@Override
    public void onClick(View view) {

        Intent intent = new Intent(this, SecondActivity.class);
        switch(view.getId()){
            case(R.id.btn1):
                intent.putExtra(EXTRA_MESSAGE, getResources().getString(R.string.tx_1));
                startActivity(intent);
                break;
            case(R.id.btn2):
                intent.putExtra(EXTRA_MESSAGE, getResources().getString(R.string.tx_2));
                startActivity(intent);
                break;

        }
    }

Everything else is like in the tutorial from Google.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question