Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Setting Listener in Kotlin ? #26

Closed
tahaak67 opened this issue Apr 24, 2019 · 4 comments
Closed

Setting Listener in Kotlin ? #26

tahaak67 opened this issue Apr 24, 2019 · 4 comments

Comments

@tahaak67
Copy link

Please excuse my question if it sounds too silly but im a beginner and im writing my app with Kotlin, i've implemented the ShowCaseView successfully and its working great when working with one ShowCaseView, im trying to make the app show several ShowCaseViews one after another but im having a hard time doing so in Kotlin, Kotlin dosn't allow overriding for local functions i've also tried to implement the GuideListener Interface in a class and then override onDismiss() fun from there but that didn't help.

below is the code i got working for a single ShowCase


fun showTut(title:String,text:String,viewID:View){
    GuideView.Builder(this)
        .setTitle(title)
        .setContentText(text)
        .setTargetView(viewID)
        .setContentTextSize(12)//optional
        .setTitleTextSize(14)//optional
    
        .setDismissType(DismissType.anywhere)
        .build()
        .show()

} 
@mreram
Copy link
Owner

mreram commented Jul 13, 2019

Duplicate of #23

@mreram mreram marked this as a duplicate of #23 Jul 13, 2019
@mreram mreram closed this as completed Jul 13, 2019
@tahaak67
Copy link
Author

tahaak67 commented Jul 13, 2019

I'm not sure how this is supposed to be a duplicate, #23 is all about a skip button but i was just having a problem with implementing the show case view in kotlin.
anyway i was able to solve my problem and accomplish to show the case views one after the other when the user taps, here is a quick example of how i did it:

       class mGuideListener:GuideListener{
        override fun onDismiss(view: View) {

        }

    }

// calling the first show case view
showTut("some text 0","more text 0",view0,0)


fun showTut(title:String,text:String,viewID:View,type:Int){

val gL: mGuideListener = mGuideListener()

    GuideView.Builder(this)
        .setTitle(title)
        .setContentText(text)
        .setTargetView(viewID)
        .setContentTextSize(12)//optional
        .setTitleTextSize(14)//optional
        .setDismissType(DismissType.anywhere)
        .setGuideListener(GuideListener(){
        gL.onDismiss(viewID)

            when (type){
            0 -> {
                showTut("First message","This is the text of the first message",view1,1)
            }
            1-> {
                showTut("Second message","This is the text of the second message",view2,2)

            }
            2 ->{
                showTut("Third message","This is the text of the 3rd message",view3,3)

            }
                3->{
                    showTut("4th message","This is the text of the 4th message",view4,4)

                }
            }
        })

        .build()
        .show()

} 

it might not be the perfect way to do it but at least it works, just wanted to share in case anyone else wants to do the same but don't know how.

@mreram
Copy link
Owner

mreram commented Jul 13, 2019

for using listener in kotlin you can use object instead of writing a class:

.setGuideListener(object :GuideListener{
    override fun onDismiss(view: View?) {
        TODO("not implemented") 
    }
})

Or using Lambda

.setGuideListener { TODO("not implemented") }

@tahaak67
Copy link
Author

for using listener in kotlin you can use object instead of writing a class:

.setGuideListener(object :GuideListener{
    override fun onDismiss(view: View?) {
        TODO("not implemented") 
    }
})

Or using Lambda

.setGuideListener { TODO("not implemented") }

Works perfectly :), thank you very much for your efforts and help.

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

No branches or pull requests

2 participants