can someone help me with why my OnClickListener won't work? Android

Posted by clayton33 on Stack Overflow See other posts from Stack Overflow or by clayton33
Published on 2010-12-29T10:50:03Z Indexed on 2010/12/29 10:53 UTC
Read the original article Hit count: 257

Filed under:
|

Is there something simple i might be missing? The "kruis" picture shows up on my ImageButton, so i'm pretty sure my main.xml is good, but when i click on the ImageButton, i get no Toast and testView does not change... been struggling for a few hours on this now, not sure what i'm doing wrong!

package com.matchit;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class matchit extends Activity {

OnClickListener cardListener;
TextView testView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    testView = (TextView)findViewById(R.id.test);

    ImageButton b1 = (ImageButton)findViewById(R.id.card1);

    b1.setImageResource(R.drawable.kruis);
    b1.setOnClickListener(cardListener);

    cardListener = new OnClickListener(){

        @Override
        public void onClick(View v) {

            testView.setText("its working");
            Toast.makeText(getApplicationContext(),
                    "its working",
                     Toast.LENGTH_LONG).show();
        }
    };
}

}

© Stack Overflow or respective owner

Related posts about android

Related posts about imagebutton