> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Conditional display in InstantSearch Android

> Learn how to improve your InstantSearch Android app when there are no results, when there's no query, or when there are errors.

This guide describes what to do when there are [no results](#handling-no-results), when there's [no query](#handling-empty-queries), or when there are [errors](#handling-errors). **Sometimes, though, users may not get any hits if their device [can't access the network or the network connection is slow](/doc/guides/building-search-ui/ui-and-ux-patterns/pagination/android#no-hits-or-is-the-search-still-in-progress).**

If you want to feature content in your search results based on a set of conditions, you can use Algolia Rules to:

* [Feature specific data from within your records](https://www.algolia.com/ecommerce-merchandising-playbook/merchandise-search-results-page//) to, for example, show promotional prices during a sales period
* [Display advertisements or promotional banners](/doc/guides/managing-results/rules/merchandising-and-promoting/how-to/add-banners).

<Note>
  To learn how to suppress InstantSearch's initial search query, check out the [conditional requests guide](/doc/guides/building-search-ui/going-further/conditional-requests/android).
</Note>

## Handling no results

Since not all queries lead to results, it's essential to let users know when this happens by **providing hints on how to adjust the query.**

### Display a message

The easiest way to display a fallback message when a query doesn't return results is to subscribe to the [`Searcher`](/doc/api-reference/widgets/instantsearch/android)'s `response` event and show your "no results" UI whenever the response has no `hits`.

```kotlin Kotlin theme={"system"}
searcher.response.subscribe {
    if (it == null || it.hitsOrNull.isNullOrEmpty()) {
        showNoResultsUI()
    } else {
        hideNoResultsUI()
    }
}
```

## Handling empty queries

By default, InstantSearch always shows you results, even when the query is empty. Depending on your use case and how you build your UI, you may only want to show results when there's a query.
To override this behavior, you can implement your own [`SearchBoxView`](/doc/api-reference/widgets/search-box/android#param-search-box-view). Instead of calling `onQueryChanged` or `onQuerySubmitted` for every query, you can call them only when the query isn't empty.

```kotlin Kotlin theme={"system"}
public class SearchBoxNoEmptyQuery(
    public val searchView: SearchView
) : SearchBoxView {

    override var onQueryChanged: Callback<String?>? = null
    override var onQuerySubmitted: Callback<String?>? = null

    init {
        searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {

            override fun onQueryTextSubmit(query: String?): Boolean {
                query?.isNotEmpty()?.let { onQuerySubmitted?.invoke(query) }
                return false
            }

            override fun onQueryTextChange(query: String?): Boolean {
                query?.isNotEmpty()?.let { onQuerySubmitted?.invoke(query) }
                return false
            }
        })
    }

    override fun setText(text: String?) {
        searchView.setQuery(text, false)
    }
}
```

## Handling errors

If an error occurs, you can display a specific piece of content to help users return to the standard state.

Subscribe to the [`Searcher`](/doc/api-reference/widgets/instantsearch/android)'s `error` event to be notified of errors.

```kotlin Kotlin theme={"system"}
searcher.error.subscribe {
    if (it != null) {
        Log.e("TAG", "Error on search $query: ${it.message}")
    }
}
```
