Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //New Activity and Intent
- // w/o the comments:
- public class MainActivity extends ActionBarActivity {
- private EditText mNameField;
- private Button mStartButton;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- 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();
- startStory();*
- });
- }
- *private void startStory();
- Intent intent = new Intent(this, StoryActivity.class);
- startActivity(intent);
- }
- //-----------------------------------------------------------------------------------------------------------------------------------------
- [1]
- StoryActivity.java
- [basic hello world template activity]
- //-----------------------------------------------------------------------------------------------------------------------------------------
- // W/ the comments
- public class MainActivity extends ActionBarActivity {
- private EditText mNameField;
- private Button mStartButton;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- 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();
- startStory();* // So when we tap on the button, were going to start our story,
- });
- }
- *private void startStory(); //listed inside OnCreate = to create something when "startStory();" is activated via "OnClickListener"
- // Create Intent:
- Intent intent = new Intent(this, StoryActivity.class); //Intent (ContextpackageContext, class)
- startActivity(intent); //we intend to start a new activity [1]
- //An intent is what we use when we intend to do something in an Android app. We usually use them to start a new task, and that task can be starting a new activity, or maybe, handing something off to another app, like a video player or a messaging app.
- }
- //-----------------------------------------------------------------------------------------------------------------------------------------
- [1]
- StoryActivity.java
- [basic hello world template activity]
Advertisement
Add Comment
Please, Sign In to add comment