Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

adding a new screen to app

I would like to create my text as a link to another screen(page) on the app. How do I do that?

4 Answers

Omar Tsai
Omar Tsai
1,704 Points

something like this

 public class MyActivity extends Activity {
 private EditText mNameField;
private Button mStartButton;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    mNameField = (EditText)findViewById(R.id.NameEditText);
    mStartButton = (Button)findViewById(R.id.StartButton);

    mStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String name = mNameField.getText().toString();
            //Toast.makeText(MyActivity.this,"Name created",Toast.LENGTH_LONG).show();
            startStory(name);

        }
    });
     }

In this first we had a Button in the layout then we made a button variable, next we initialized the button using the mStartButton = (Button)findViewById(R.id.StartButton); and then made a onclicklistener for the button.

Albert Evangelista
Albert Evangelista
27,686 Points

its like adding a button on the screen but instead of a button you put a TextView on the screen and then you make the onClickListener for the TextView and in that listener you launch an activity using startActivity.

how do you create an onClickListener?

Omar Tsai
Omar Tsai
1,704 Points

Pretty much you make a onclicklistener for the textview which directs you to a new layout.

how do you create an onClickListener?