android-simple-tooltip icon indicating copy to clipboard operation
android-simple-tooltip copied to clipboard

verify dismissed? Tooltip has ben dismissed.

Open Fahad-pnw opened this issue 6 years ago • 3 comments

hi, here's a small code, on a custom modal, double tapping the button... java.lang.IllegalArgumentException: Tooltip has ben dismissed.

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById(R.id.btn_modal_custom).setOnClickListener(this)
        val textView1: TextView? = TextView(this)
        val textView2: TextView? = TextView(this)
        textView1!!.text = "Yout text here"
        textView2!!.text = "some more text"

        val layout: LinearLayout? = LinearLayout(this)
        layout!!.addView(textView1)
        layout.addView(textView2)


        val view:View = findViewById(R.id.btn_modal_custom)
        val tooltip = SimpleTooltip.Builder(this)
                .anchorView(view)
                .text(R.string.btn_modal_custom)
                .gravity(Gravity.BOTTOM)
                .modal(true)

                .animated(true)
                .animationDuration(2000)
                .contentView(layout, 0)
                .focusable(true)
                .build()

        view.setOnClickListener({

            if (tooltip.isShowing) {
                
                tooltip.dismiss()
                
            } else
            {
                tooltip.show()
            }

        })

    }

Fahad-pnw avatar Mar 29 '18 11:03 Fahad-pnw

I think I do not understand, what's the problem?

douglasjunior avatar Mar 30 '18 12:03 douglasjunior

@Fahad-pnw you should instead be using something like (sorry code is in java because I do not have time to convert it in kotlin so its kinda like pseudocode).

val tooltip = SimpleTooltip.Builder(this)
                .anchorView(view)
                .text(R.string.btn_modal_custom)
                .gravity(Gravity.BOTTOM)
                .modal(true)
                .onDismissListener(new SimpleTooltip.OnDismissListener() {
                @Override
                public void onDismiss(SimpleTooltip tooltip) {
                    listener.onTooltipDismissedForView(view.getId());
                    }
                })
                .animated(true)
                .animationDuration(2000)
                .contentView(layout, 0)
                .focusable(true)
                .build()

Here, onTooltipDismissedForView(@IdRes viewId) is just a callback. This way you could perhaps detect which view the tooltip was dismissed for, instead of setting a OnclickListener for every view.

poppito avatar Apr 21 '18 23:04 poppito

based on the documentation provided, you should not take action from variables that have been defined before calling. You can directly create the object when you want to do a show action

view.setOnClickListener({
        SimpleTooltip.Builder(this)
                .anchorView(view)
                .text(R.string.btn_modal_custom)
                .gravity(Gravity.BOTTOM)
                .modal(true)
                .animated(true)
                .animationDuration(2000)
                .contentView(layout, 0)
                .focusable(true)
                .build()
                .show()
})

rakaadinugroho avatar Apr 23 '19 04:04 rakaadinugroho