Guest User

MainActivity.java

a guest
Jun 13th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package com.example.crystalball;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.support.v7.app.ActionBarActivity;
  6. import android.view.Menu;
  7. import android.view.MenuItem;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.TextView;
  11.  
  12. public class MainActivity extends Activity {
  13.  
  14.     private CrystalBall mCrystalBall = new CrystalBall();
  15.    
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.        
  21.         // Declare our View variables and assign them Views from the layout file
  22.         final TextView answerLabel = (TextView) findViewById(R.id.textView1);
  23.         Button getAnswerButton = (Button) findViewById(R.id.button1);
  24.        
  25.         getAnswerButton.setOnClickListener(new View.OnClickListener() {
  26.            
  27.             public void onClick(View v) {
  28.                 String answer = mCrystalBall.getAnAnswer();
  29.                
  30.                 answerLabel.setText(answer);
  31.                
  32.             }
  33.         });
  34.     }
  35.  
  36.     @Override
  37.     public boolean onCreateOptionsMenu(Menu menu) {
  38.  
  39.         // Inflate the menu; this adds items to the action bar if it is present.
  40.         getMenuInflater().inflate(R.menu.main, menu);
  41.         return true;
  42.     }
  43.  
  44.     @Override
  45.     public boolean onOptionsItemSelected(MenuItem item) {
  46.         // Handle action bar item clicks here. The action bar will
  47.         // automatically handle clicks on the Home/Up button, so long
  48.         // as you specify a parent activity in AndroidManifest.xml.
  49.         int id = item.getItemId();
  50.         if (id == R.id.action_settings) {
  51.             return true;
  52.         }
  53.         return super.onOptionsItemSelected(item);
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment