Redirect to different Activity with Views

0

Good morning, I'm making an App in which different images are in the form of a circle, and in each of those images you have to address a different view.

This is how the App would look with the images loaded.

The problem comes when I click on any of the images, since it does not matter which one I always direct to the last view I loaded.

To put less code what I did was just put two images that should address different views. Something like this:

The code when I do the OnClickListener would be this:

public void actionViews(){
   c0.setOnClickListener(this);
   c2.setOnClickListener(this);

   LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
   addContentView(c0, params);
   addContentView(c2, params);
}

@Override
public void onClick(View v) {
    if (v ==  c0){
        try{
            Intent intent = new Intent(inicio.this, ciclo.class);
            startActivity(intent);
        }catch (Exception e){}
    }else if(v == c2()){
        try{
            Intent intent = new Intent(inicio.this, chat.class);
            startActivity(intent);
         }catch (Exception e){}
    }
}

In this case, what always happens is that when I click on any of the two images, it always directs the chat class.

I create and upload the images in the same class in the following way:

static public class CircleView extends View implements View.OnClickListener {
Paint paint;
Object[] circulos;
Bitmap imagen;

//variables
float CX;
float CY;
float CR;

//tag
String btnTag = "";

public CircleView(Context context, float x, float y, float r, Bitmap img, String tag) {
    super(context);
    CX = x;
    CY = y;
    CR = r;
    imagen = img;
    paint = new Paint();
    btnTag = tag;
}

@Override
public void onDraw(Canvas canvas) {
    paint.setColor(Color.GREEN);
    canvas.drawBitmap(imagen, CX-(CR/2), CY-(CR/2), paint);
    this.setTag(btnTag);
}

This simply puts the image in the points (x, y) that I send you.

If you could help me, I would really appreciate it.

    
asked by dieroste 21.10.2016 в 18:15
source

1 answer

1

If your previous method works with the chat method, and you copied the code as you have it, I can see that you are missing parentheses in the first if , in the c0 . Try adding them, if it does not work, I can help you modify that code so you can handle the clicks in a different way. You could use a switch .

 @Override
    public void onClick(View v) {
        if (v ==  c0()){
            try{
                Intent intent = new Intent(inicio.this, ciclo.class);
                startActivity(intent);
            }catch (Exception e){}
        }else if(v == c2()){
            try{
                Intent intent = new Intent(inicio.this, chat.class);
                startActivity(intent);
             }catch (Exception e){}
        }

You should add a id to your buttons and click on the View and compare the View with the id using switch .

    
answered by 21.10.2016 в 18:53