baron dune
baron dune

Reputation: 367

Android onclick event?

I'm officially going crazy as to why this is not working properly. I have tried pretty much everything but it's not calling the onclick event properly?

This is my error message that I am getting after the = sign

The type new DialogInterface.OnClickListener(){} must implement the
inherited abstract method
DialogInterface.OnClickListener.onClick(DialogInterface, int)

and keeps telling me to add unimplemented items. But I thought it was implemented with the View v?

Can anyone help me understand as to why this is not working properly?

Even if I implement the onclick listener in the beginning it's still not working? I'm so confused?

<ImageView
    android:id="@+id/eraserBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dip"
    android:layout_weight="1"
    android:background="@drawable/selector_tool_bg"
    android:src="@drawable/eraser" />


            mEraserBtn = (ImageView) findViewById(R.id.eraserBtn);

             mEraserBtn.setOnClickListener(new OnClickListener){
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    int nBtnID = mEraserBtn.getId();
                    // If the mode is not changed, open the setting view. If the mode is same, close the setting view. 
                    if(nBtnID == mEraserBtn.getId()){
                        if(mSCanvas.getCanvasMode()==SCanvasConstants.SCANVAS_MODE_INPUT_ERASER){
                            mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER);
                        }
                        else{
                            mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
                            mSCanvas.showSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER, false);
                        }
                    }   
                }
                });

Upvotes: 2

Views: 281

Answers (2)

Simon Dorociak
Simon Dorociak

Reputation: 33505

The type new DialogInterface.OnClickListener(){} must implement the inherited abstract method DialogInterface.OnClickListener.onClick(DialogInterface, int)

You have imported incorrect OnClickListener. Your import has to be

import android.view.View.OnClickListener;

and not

import android.content.DialogInterface.OnClickListener;

Both have same name(easy to make a mistake) but they are different. Be careful.

Upvotes: 3

Victor Laerte
Victor Laerte

Reputation: 6556

Probably you have another ClickListener for Dialog in your application, or you're importing the wrong ClickListener, try to do that and test if is it:

         mEraserBtn.setOnClickListener(new android.view.View.OnClickListener){

If it works, you need to organize your imports as mentioned before

Upvotes: 0

Related Questions