coolcat
coolcat

Reputation: 79

Multiple OnClickListener fix

I am trying to have 10 image buttons in one activity and i would like to have all my buttons clicks in this one activity.I have this code which i think is right for my needs but where i am stuck is..In my java code i don't see the intent to open a new activity.

   package com.baha.beallhasall;

   import android.app.Activity;
   import android.content.Intent;
   import android.graphics.Typeface;
   import android.os.Bundle;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.Button;
   import android.widget.ImageButton;
   import android.widget.TextView;

   public class FirstActivityPage extends Activity implements OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_one);
    ImageButton btn1 = (ImageButton)findViewById(R.id.imageButton1);
    ImageButton btn2 = (ImageButton)findViewById(R.id.imageButton2);
    ImageButton btn3 = (ImageButton)findViewById(R.id.imageButton3);
    btn1.setOnClickListener(this);
    btn2.setOnClickListener(this);
     btn3.setOnClickListener(this);
   }

     @Override
     public void onClick(View v) {
    switch(v.getId()){
        case R.id.imageButton1:
            break;                // intent ?????//
        case R.id.imageButton2:
            break;
        case R.id.imageButton3:
            break;
    }
    }
   }

So image button1 on click is fine but when its clicked nothing happens. Do i need to implement and intent somewhere to open it. I am clueless at the moment

Something like this that is missing

    Intent myIntent = new Intent(view.getContext(), FourActivityPage.class);
            startActivityForResult(myIntent, 0);

Thanks

Upvotes: 0

Views: 114

Answers (1)

La bla bla
La bla bla

Reputation: 8708

You should implement pretty much exactly what you say that it missing.

Depending on the image that was clicked (your switch-case statement) you should declare an Intent and start it

Intent intent = new Intent(FirstActivityPage.this, SecondActivityPage.class);
startActivity(intent);

More info here

Upvotes: 1

Related Questions