Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead #63

Closed
wood23636 opened this issue Jul 26, 2015 · 13 comments

Comments

@wood23636
Copy link

Hi, I want to add a whellview to dialogplus, it extend from spinner. but throw a exception.

07-25 22:13:30.493: E/AndroidRuntime(13740): java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.jyxtec.wheel.TosAdapterView.setOnClickListener(TosAdapterView.java:803)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.setClickListener(DialogPlus.java:315)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:300)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:297)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:297)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:297)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.assignClickListenerRecursively(DialogPlus.java:297)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.createView(DialogPlus.java:259)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.initContentView(DialogPlus.java:227)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlus.(DialogPlus.java:111)
07-25 22:13:30.493: E/AndroidRuntime(13740): at com.orhanobut.dialogplus.DialogPlusBuilder.create(DialogPlusBuilder.java:265)

@wood23636
Copy link
Author

version 1.10

@orhanobut
Copy link
Owner

can you show the whole implementation of dialogplus?

@wood23636
Copy link
Author

           WheelView monthWheel = (WheelView)viewGroup.findViewById(R.id.month_wheel);

//
//
//
monthWheel.setScrollCycle(true);
NumberAdapter monthAdapter = new NumberAdapter(monthArray);
monthWheel.setAdapter(monthAdapter);
monthWheel.setOnItemSelectedListener(mWheelViewListener);
monthWheel.setUnselectedAlpha(0.5f);
monthWheel.setOnItemClickListener(new TosAdapterView.OnItemClickListener() {
@OverRide
public void onItemClick(TosAdapterView<?> tosAdapterView, View view, int i, long l) {

                }
            });

            DialogPlus dialogPlus = DialogPlus.newDialog(getActivity())
                    .setContentHolder(new ViewHolder(viewGroup))
                    .setGravity(Gravity.BOTTOM)
                    .setCancelable(true)
                    .setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(DialogPlus dialogPlus, Object o, View view, int i) {

                        }
                    })
                    .create();
            dialogPlus.show();

@orhanobut
Copy link
Owner

When you use ViewHolder, you can't use OnItemClickListener, if you want to have click events of the individual views, use OnClickListener, or if you already handle it by yourself, just remove all click listeners from dialogplus.

@wood23636
Copy link
Author

yes I have removed all click listeners before. But it throw the exception too.

DialogPlus dialogPlus = DialogPlus.newDialog(getActivity())
                        .setContentHolder(new ViewHolder(viewGroup))
                        .setGravity(Gravity.BOTTOM)
                        .setCancelable(true)
                        .create();
                dialogPlus.show();

@wood23636
Copy link
Author

I think that, when I give a custom viewgroup, the dialogplus also set the click event all children. But when I set a spinner in it. spinner can not set click event. android throw a exception. Can I forbidden the click event?

@orhanobut
Copy link
Owner

Yes, it seems this is the exact reason and unfortunately there is no this option, but we should add this for these situations. You can only avoid this by creating spinner dynamically, dialogplus adds clicklistener only if the view has an id.

@wood23636
Copy link
Author

oh! may be I can remove the id and try find it by the tag or parent find chid?

@orhanobut
Copy link
Owner

That could also work but out of box, we already avoid to set clicklistener for adapterview. Need to check thorougly for this issue.

@wood23636
Copy link
Author

ok. I try to remove the id and get it work. Thanks.

@orhanobut
Copy link
Owner

cheers 👍

@bigggge
Copy link

bigggge commented Jun 9, 2016

@wood23636 Can you show me your code,I can't solve it, Thanks.

@Djek-grif
Copy link

In my case I try to add onClickListener for spinner and I've got the same problem. I've crated workaround with touch listener:

someSpinner.setOnTouchListener { _, event -> onTouchSomeSpinner(event)}

fun onTouchSomeSpinner(event: MotionEvent): Boolean {
        if(event.action == MotionEvent.ACTION_UP) {
            view.hideKeyBoard()
            view.analyticsEvent()
            ...
        }
        return false
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants