Calling new Activity via an ImageView

0

I need to call a new Activity through click on a ImageView .

Follow my code:

final ImageView botaoAbrirMesas = (ImageView) findViewById(R.botoes_laucher.openMesas);

    botaoAbrirMesas.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent it = new Intent();
            it.setClass(null, PrincipalActivity.class);

            startActivity(it);
        }
    });

However, running the application terminates due to an error. Is this the right way to use or can not use click on a ImageView ?

    
asked by anonymous 02.04.2014 / 19:36

1 answer

2

I think the problem is with you passing null on method setClass .

Replace your code with this one:

Intent intent = new Intent(Main.this, PrincipalActivity.class);
startActivity(intent);  

Replace Main.this with NomeDaSuaActividade.this

If you want to use the method setClass replace null with NomeDaSuaActividade.this

    
02.04.2014 / 20:43