0

Here is My Code,I need a to put something inside{} to link the button to new class or activity like second page.java :

public void addListenerOnButton() {

        ImageButton imageButton = (ImageButton) findViewById(R.id.imageButton1);

        imageButton.setOnClickListener(new OnClickListener() {


/*What can I put here to open new class 
,I mean another activity like secondp.java.*/



            }

I Tried to put below code, but I got the following error:

The constructor Intent(new View.OnClickListener(){}, Class<List>) is undefined

Code

@Override
            public void onClick(View arg0) {
                Intent k = new Intent(this,Secondp.class);
                startActivity(k);
4

3 に答える 3

1

変化する

Intent k = new Intent(this,Secondp.class);

Intent k = new Intent(NameofyourcurrentActivity.this,Secondp.class);

thisキーワードだけを使用して、のオブジェクトを渡しますOnClickListener

于 2013-01-23T01:51:39.947 に答える
1

単純

間違ったthis:)を使用すると、コンテキストが必要なときにクラスがIntentに
this渡されます。OnClickListener

使用する:

startActivity(new Intent(NameofyourcurrentActivity.this,Second.class));
于 2013-01-23T02:07:11.243 に答える
0

try removing the "this" clause, cause when you use the "this" in your code, it is referring to the onclicklistener class. if you wants to add in the context, make an reference of your context before the methods and use that instead.

于 2013-01-23T01:50:55.453 に答える