2012-06-20 4 views
0

это мой пользовательский диалог класс:андроид пользовательский диалог IMAGEBUTTON onclicklistener

package com.WhosAround.Dialogs; 

import com.WhosAround.AppVariables; 
import com.WhosAround.R; 
import com.WhosAround.AsyncTasks.LoadUserStatus; 
import com.WhosAround.Facebook.FacebookUser; 

import android.app.Dialog; 
import android.content.Context; 
import android.graphics.drawable.Drawable; 
import android.view.MotionEvent; 
import android.view.View; 
import android.widget.ImageButton; 
import android.widget.ImageView; 
import android.widget.TextView; 

public class MenuFriend extends Dialog{ 

    private FacebookUser friend; 
    private AppVariables app; 

    public MenuFriend(Context context, FacebookUser friend) { 
     super(context, android.R.style.Theme_Translucent_NoTitleBar); 
     this.app = (AppVariables) context.getApplicationContext(); 
     this.friend = friend; 
    } 

    public void setDialog(String userName, Drawable userProfilePicture) 
    { 
     setContentView(R.layout.menu_friend); 
     setCancelable(true); 
     setCanceledOnTouchOutside(true);   
     TextView name = (TextView) findViewById(R.id.menu_user_name); 
     TextView status = (TextView) findViewById(R.id.menu_user_status); 
     ImageView profilePicture = (ImageView) findViewById(R.id.menu_profile_picture); 
     ImageButton closeButton = (ImageButton) findViewById(R.id.menu_close); 
     name.setText(userName);   
     profilePicture.setImageDrawable(userProfilePicture); 

     if (friend.getStatus() != null) 
      status.setText(friend.getStatus()); 
     else 
      new LoadUserStatus(app, friend, status).execute(0); 
     closeButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       dismiss(); 

      } 
     }) 

    } 


} 

почему-то затмение говорит мне следующие ошибки на closeButton IMAGEBUTTON:

The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new DialogInterface.OnClickListener(){}) 

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

The method onClick(View) of type new DialogInterface.OnClickListener(){} must override or implement a supertype method 

почему?

ответ

0

Интерфейс OnClickListener входит в подклассы. Возможно, вы импортируете DialogInterface.OnClickListener, а не View.OnClickListener.

Различные подклассы интерфейса имеют разные реализации onClick().

public interface View.OnClickListener() { 
    // This implementation gives you a reference to the View that was clicked. 
    onClick(View v); 
} 
public interface DialogInterface.OnClickListener() { 
    // This implementation gives you references to the dialog in which the click happend 
    onClick(DialogInterface dialog, int which); 
} 

Измените ваш setOnClickListener к этому:

closeButton.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      dismiss(); 

     } 
    }) 
Смежные вопросы