GAIUS12100
GAIUS12100

Reputation: 45

Kotlin SearchView how to adjust back button

when I search the recyclerview item with my app's search bar after I see the recyclerview item It should have gone back to recyclerview list when I press back button but app closes itself instead of that.

Here is my codes ;

//SEARCH
    searchBtn.setOnClickListener {
        url = ""

        postArrayList = ArrayList()
        postArrayList.clear()

        val query = searchEt.text.toString().trim()
        if(TextUtils.isEmpty(query)){
            loadPosts()
        } else {
            searchPosts(query)
        }
    }

What can I do for this ? Thank you

Upvotes: 1

Views: 77

Answers (1)

Yotaka Yomoto
Yotaka Yomoto

Reputation: 19

You need to use onBackPressed button. Detail information is here: https://developer.android.com/guide/navigation/navigation-custom-back

Upvotes: 1

Related Questions