Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.activity_menu_01);
  5. }
  6.  
  7. @Override
  8. public boolean onCreateOptionsMenu(Menu menu) {
  9. // Inflate the menu; this adds items to the action bar if it is present.
  10. getMenuInflater().inflate(R.menu.menu_menu_01, menu);
  11. return true;
  12. }
  13.  
  14. @Override
  15. public boolean onOptionsItemSelected(MenuItem item) {
  16. // Handle action bar item clicks here. The action bar will
  17. // automatically handle clicks on the Home/Up button, so long
  18. // as you specify a parent activity in AndroidManifest.xml.
  19. int id = item.getItemId();
  20.  
  21. //noinspection SimplifiableIfStatement
  22. if (id == R.id.action_settings) {
  23. return true;
  24. }
  25.  
  26. return super.onOptionsItemSelected(item);
  27.  
  28. }
  29. }
  30.  
  31. <ImageButton
  32. android:id="@+id/your_id"
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"/>
  35.  
  36. ImageButton myButton = (ImageButton) findViewById(R.id.the_button_you_created_on_the_layout.xml_file);
  37.  
  38. myButton.setOnClickListener(new View.OnClickListner(){
  39. // When the button is pressed/clicked, it will run the code below
  40. @Override
  41. public void onClick(){
  42. // Intent is what you use to start another activity
  43. Intent intent = new Intent(this, YourActivity.class);
  44. startActivity(intent);
  45. }
  46. });
  47.  
  48. @Override
  49. protected void onCreate(Bundle savedInstanceState) {
  50. super.onCreate(savedInstanceState);
  51. setContentView(R.layout.activity_menu_01);
  52. ImageButton button = (ImageButton) findViewById(R.id.my_button);
  53. final Context context = this;
  54. button.setOnClickListener(new View.OnClickListner(){
  55. @Override
  56. public void onClick(View v){
  57. Intent intent = new Intent(context, NewActivity.class);
  58. startActivity(intent);
  59. }
  60. });
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement