Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Android TNB Make Your App Interactive
- //---------------------------------------------------------------------------------------------------------------------------------------
- //strings.xml
- <resources>
- <string name="app_name">Event Handling: How To Make Your App Interactive</string>
- <string name="hello_world">Hello world!</string>
- <string name="action_settings">Settings</string>
- <string name="message_text">Hello</string>
- <string name="button_text">Click me Hoss</string>
- </resources>
- //---------------------------------------------------------------------------------------------------------------------------------------
- //MainActivity.java
- package com.thenewboston.eventhandlinghowtomakeyourappinteractive;
- import android.support.v7.app.ActionBarActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class MainActivity extends ActionBarActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Button buckysButton = (Button)findViewById(R.id.buckysButton);
- buckysButton.setOnClickListener(
- new Button.OnClickListener(){
- public void onClick(View v){
- TextView buckysText = (TextView)findViewById(R.id.buckysText);
- buckysText.setText("Good Job Hoss!");
- }
- }
- );
- buckysButton.setOnLongClickListener(
- new Button.OnLongClickListener(){
- public boolean onLongClick(View v){
- TextView buckysText = (TextView)findViewById(R.id.buckysText);
- buckysText.setText("Holy carp, that was a long one!");
- return true; //whenever we have an OnLongClick we need a "return true"
- }
- }
- );
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement