Advertisement
yo2man

Android TNB 13. Create an Interface w/ Java

Jun 1st, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. //Android TNB 13. Create an Interface w/ Java
  2. MainActivity.Java of the Allison project taught by The New Boston
  3.  
  4. package com.thenewboston.allison;
  5.  
  6. import android.support.v7.app.ActionBarActivity;
  7. import android.os.Bundle;
  8. import android.view.Menu;
  9. import android.view.MenuItem;
  10. import android.widget.RelativeLayout;
  11. import android.widget.Button;
  12.  
  13. public class MainActivity extends ActionBarActivity {
  14.  
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.  
  19.         RelativeLayout buckysLayout = new RelativeLayout(this); //Create Layout
  20.         Button redButton = new Button(this);  //Create Button
  21.  
  22.         buckysLayout.addView(redButton); //add Button to Layout (Button is now Child of Layout)
  23.         setContentView(buckysLayout);  //Set this activities content/display to this view
  24.     }
  25.  
  26.     @Override
  27.     public boolean onCreateOptionsMenu(Menu menu) {
  28.         // Inflate the menu; this adds items to the action bar if it is present.
  29.         getMenuInflater().inflate(R.menu.menu_main, menu);
  30.         return true;
  31.     }
  32.  
  33.     @Override
  34.     public boolean onOptionsItemSelected(MenuItem item) {
  35.         // Handle action bar item clicks here. The action bar will
  36.         // automatically handle clicks on the Home/Up button, so long
  37.         // as you specify a parent activity in AndroidManifest.xml.
  38.         int id = item.getItemId();
  39.  
  40.         //noinspection SimplifiableIfStatement
  41.         if (id == R.id.action_settings) {
  42.             return true;
  43.         }
  44.  
  45.         return super.onOptionsItemSelected(item);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement