tiper / MaterialSpinner

Implementation of a Material Spinner for Android with TextInputLayout functionalities
Apache License 2.0
130 stars 30 forks source link

setOnClickListener is blocked but I need to use it #19

Closed MKevin3 closed 4 years ago

MKevin3 commented 4 years ago

Due to some code I inherited I need to use setOnClickListener. Basically I want the look and feel of the spinner but when it is clicked on a separate dialog appears. I am not using any of the other features of the spinner, no drop down, etc. but I need the look with the title over the spinner etc.

I do fully use of your spinner in a number of other areas in the code, this area just happens to be a hackfest.

The code in MaterialSpinner.kt at line 319 blocks this usage - as hacky as it might be.

override fun setOnClickListener(l: OnClickListener?) {
    throw RuntimeException(
        "Don't call setOnClickListener." +
                "You probably want setOnItemClickListener instead."
    )
}

Really need this check to be optional

MKevin3 commented 4 years ago

To get around this issue I put a transparent View on top of the MaterialSpinner and get the onClickListener from there.

tiper commented 4 years ago

Hi @MKevin3, have you tried setting a OnFocusChangeListener instead?

tiper commented 4 years ago

Possible duplicate of #10

tiper commented 4 years ago

Hi @MKevin3 any feedback on this?

MKevin3 commented 4 years ago

I just put a view on top of the MaterialSpinner as far as Z-Order is concerned and grab the listener there. While I understand why MaterialSpinner gives the warning in the log as it is a common mistake I don't feel it should be a "and there is NO way you can do this" exception.

tiper commented 4 years ago

@MKevin3 You should be able to achieve the same functionality without the need of an extra view using the OnFocusChangeListener.

When you click on this view it also gains focus, therefore the focus callback will be triggered, and you will be able to achieve the same effect. Take a look at the sample for a simple example.

tiper commented 4 years ago

Hi @MKevin3 did you had the time to take a look at tying OnFocusChangeListener?