Reputation: 1
I need to import following two different library
import android.content.DialogInterface.OnClickListener;
import android.view.View.OnClickListener;
as I want both DialogInterface.OnClickListener
and View.OnClickListener
in the same activity!!
how can I handle this?!!
because when I use both onClickListener
I got an error!
Is it possible to have two different onClickListener
in one class?!!
Upvotes: 0
Views: 296
Reputation: 133560
Make your class implement the interfaces
extends Activity implements View.OnClickListener,DialogInterface.OnClickListener
Then
@Override
public void onClick(DialogInterface dialog, int which) {
// do something
}
@Override
public void onClick(View v) {
// dosomething
}
Upvotes: 0
Reputation: 3179
You could import one and call the next onClickListener
as say Dialog.onClickListener
Upvotes: 0
Reputation: 157447
one way to go could be
public class MyClass implements DialogInterface.OnClickListener, View.OnClickListener {
}
Upvotes: 1
Reputation: 359826
Import just android.content.DialogInterface
and android.view.View
. Then you'll be able to reference the different OnClickListener classes by qualifying them with the parent class, as in
DialogInterface.OnClickListener foo = ...;
// and
View.OnClickListener bar = ...;
You're lucky, in this case, because the two classes with the same name happen to be nested classes. If they weren't - the only difference being the package name, you'd have to use the fully-qualified class name of at least one of them:
android.content.DialogInterface.OnClickListener foo = ...;
OnClickListener bar = ...;
// or
OnClickListener foo = ...;
android.view.View.OnClickListener bar = ...;
// or
android.content.DialogInterface.OnClickListener foo = ...;
android.view.View.OnClickListener bar = ...;
which is neither fun to read nor write.
Upvotes: 2