Guest User

MojagłównaActivity

a guest
Jan 7th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. package com.example.myapp;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.support.v7.app.ActionBarActivity;
  5. import android.view.Menu;
  6. import android.view.MenuItem;
  7. import android.view.View;
  8. import android.widget.AdapterView;
  9. import android.widget.AdapterView.OnItemSelectedListener;
  10. import android.widget.ArrayAdapter;
  11. import android.widget.Button;
  12. import android.widget.Spinner;
  13.  
  14. public class MainActivity extends ActionBarActivity implements OnItemSelectedListener {
  15.  
  16. @Override
  17. protected void onCreate(Bundle savedInstanceState)
  18. {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.activity_main);
  21. final Button click=(Button)findViewById(R.id.button2);
  22. click.setOnClickListener(new View.OnClickListener(){ //nowy actionlistener
  23. @Override
  24. public void onClick(View v) {
  25. Intent activitylauncher=new Intent(MainActivity.this,AboutActivity.class);
  26. //tworzenie nowej intencji Create an intent for a specific component.
  27. startActivity(activitylauncher);
  28. }
  29. });
  30. final Button click2=(Button)findViewById(R.id.button1);
  31. click2.setOnClickListener(new View.OnClickListener() { //nowy actionlistener
  32. @Override
  33. public void onClick(View v) {
  34. Intent activitylauncher=new Intent(MainActivity.this,RandomActivity.class);
  35. //tworzenie nowej intencji Create an intent for a specific component.
  36. startActivity(activitylauncher);
  37. }
  38. });
  39. Spinner spinner = (Spinner) findViewById(R.id.spinner1);
  40. // Create an ArrayAdapter using the string array and a default spinner layout
  41. ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.recipie_array, android.R.layout.simple_spinner_item);
  42. // Specify the layut to use when the list of choices appears
  43. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  44. // Apply the adapter to the spinner
  45. spinner.setAdapter(adapter);
  46. }
  47.  
  48. public void onItemSelected(AdapterView<?> parent, View view,
  49. int pos, long id) {
  50. Spinner spinner = (Spinner) findViewById(R.id.spinner1);
  51. spinner.setOnItemSelectedListener(this);
  52.  
  53.  
  54. if( parent.getItemAtPosition(pos).equals(1))
  55. {
  56.  
  57. Intent intent3 = new Intent(MainActivity.this, SpinnerActivity.class);
  58.  
  59. startActivity(intent3);
  60. }
  61.  
  62. if( parent.getItemAtPosition(pos).equals(2))
  63. {
  64.  
  65. Intent intent3 = new Intent(MainActivity.this, SpinnerActivity.class);
  66.  
  67. startActivity(intent3);
  68. }
  69. if( parent.getItemAtPosition(pos).equals(3))
  70. {
  71.  
  72. Intent intent3 = new Intent(MainActivity.this, SpinnerActivity.class);
  73.  
  74. startActivity(intent3);
  75. }
  76.  
  77. }
  78.  
  79. // An item was selected. You can retrieve the selected item using
  80. // parent.getItemAtPosition(pos)
  81.  
  82.  
  83. public void onNothingSelected(AdapterView<?> parent) {
  84. // Another interface callback
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91. @Override
  92. public boolean onCreateOptionsMenu(Menu menu) {
  93. // Inflate the menu; this adds items to the action bar if it is present.
  94. getMenuInflater().inflate(R.menu.main, menu);
  95. return true;
  96. }
  97.  
  98.  
  99.  
  100. @Override
  101.  
  102. public boolean onOptionsItemSelected(MenuItem item){
  103. // Handle action bar item clicks here. The action bar will
  104. // automatically handle clicks on the Home/Up button, so long
  105. // as you specify a parent activity in AndroidManifest.xml.
  106. int id = item.getItemId();
  107. if (id == R.id.action_settings) {
  108. return true;
  109. }
  110. return super.onOptionsItemSelected(item);
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment