Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_menu_01);
- }
- @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_menu_01, 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);
- }
- }
- <ImageButton
- android:id="@+id/your_id"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- ImageButton myButton = (ImageButton) findViewById(R.id.the_button_you_created_on_the_layout.xml_file);
- myButton.setOnClickListener(new View.OnClickListner(){
- // When the button is pressed/clicked, it will run the code below
- @Override
- public void onClick(){
- // Intent is what you use to start another activity
- Intent intent = new Intent(this, YourActivity.class);
- startActivity(intent);
- }
- });
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_menu_01);
- ImageButton button = (ImageButton) findViewById(R.id.my_button);
- final Context context = this;
- button.setOnClickListener(new View.OnClickListner(){
- @Override
- public void onClick(View v){
- Intent intent = new Intent(context, NewActivity.class);
- startActivity(intent);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement