title: How to implement a SearchView to search specific buttons in a LinearLayout?
body: <p>I'm opening this discussion because I need help for a school project.</p>
  <p>At the moment, I have a scrollable activity with some buttons, everything is built like this:
  a constraint layout, with SearchView, ScrollView and a BottomNavigationBar, and inside the ScrollView there's a LinearLayout with all my buttons.</p>
  <p>Here is the full xml file:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  
  
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_height=&quot;match_parent&quot;
      android:layout_width=&quot;match_parent&quot;
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;&gt;
  
  
      &lt;SearchView
          android:id=&quot;@+id/BarraRicerca&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;50dp&quot;
          android:layout_marginTop=&quot;10dp&quot;
          android:gravity=&quot;top&quot;
          android:iconifiedByDefault=&quot;false&quot;
          android:imeOptions=&quot;actionDone&quot;
          android:queryHint=&quot;Cerca un tutorial&quot;
          android:labelFor=&quot;@id/BarraRicerca&quot;
          android:suggestionRowLayout=&quot;@color/white&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
  
      &lt;ScrollView
          android:id=&quot;@+id/scrollView2&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:layout_alignParentTop=&quot;true&quot;
          android:layout_weight=&quot;1&quot;
          android:fillViewport=&quot;false&quot;
          android:orientation=&quot;vertical&quot;
          android:padding=&quot;10dp&quot;
          android:layout_marginTop=&quot;60dp&quot;
          app:layout_constraintBottom_toTopOf=&quot;@id/BottomBar&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@id/BarraRicerca&quot;&gt;
  
  
          &lt;LinearLayout
              android:id=&quot;@+id/Linearlayout&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;match_parent&quot;
              android:orientation=&quot;vertical&quot;
              tools:context=&quot;com.example.Flipper.FlipperList&quot;&gt;
  
              &lt;Button
                  android:id=&quot;@+id/FlintstonesF&quot;
                  android:layout_width=&quot;300dp&quot;
                  android:layout_height=&quot;49dp&quot;
                  android:layout_gravity=&quot;center_horizontal&quot;
                  android:layout_margin=&quot;100dp&quot;
                  android:text=&quot;Flintstones&quot; /&gt;
  
              &lt;Button
                  android:id=&quot;@+id/tutorial2&quot;
                  android:layout_width=&quot;300dp&quot;
                  android:layout_height=&quot;49dp&quot;
                  android:layout_gravity=&quot;center_horizontal&quot;
                  android:layout_margin=&quot;200dp&quot;
                  android:layout_weight=&quot;1&quot;
                  android:text=&quot;ciao&quot; /&gt;
  
              &lt;Button
                  android:id=&quot;@+id/tutorial3&quot;
                  android:layout_width=&quot;300dp&quot;
                  android:layout_height=&quot;49dp&quot;
                  android:layout_gravity=&quot;center_horizontal&quot;
                  android:layout_margin=&quot;100dp&quot;
                  android:layout_weight=&quot;1&quot;
                  android:text=&quot;hello&quot; /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/ScrollView&gt;
  
      &lt;com.google.android.material.bottomnavigation.BottomNavigationView
          android:id=&quot;@+id/BottomBar&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;60dp&quot;
          android:layout_marginStart=&quot;0dp&quot;
          android:layout_marginEnd=&quot;0dp&quot;
          android:layout_gravity=&quot;bottom&quot;
          android:background=&quot;?android:attr/windowBackground&quot;
          app:layout_constraintLeft_toLeftOf=&quot;parent&quot;
          app:layout_constraintRight_toRightOf=&quot;parent&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;/&gt;
  
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>and the result is this, everything works</p>
  <p><a href="https://i.stack.imgur.com/0hil6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0hil6.png" alt="enter image description here" /></a></p>
  <p>Now I need to implement the SearchView to actually search through my buttons, For example if I search Flintstones (or Flint, or Fli etc.) I want the Flintstones button to be the only one shown. The same goes for &quot;ciao&quot; and so on, I will obviously have more buttons than these.</p>
  <p>I tried every possible solution I found on the internet but nothing seems to work. This is my code</p>
  <pre><code>package com.example.Flipper
  
  import android.content.Intent
  import android.os.Bundle
  import android.view.View
  import android.widget.*
  import androidx.appcompat.app.AppCompatActivity
  import androidx.core.view.isVisible
  import com.example.pinballacademy.R
  
  
  class FlipperList : AppCompatActivity() {
      val passaFlintstones: Button get() = findViewById(R.id.FlintstonesF)
      val bottone2: Button get() = findViewById(R.id.tutorial2)
      val bottone3: Button get() = findViewById(R.id.tutorial3)
      val searchbar: SearchView get() = findViewById(R.id.BarraRicerca)
      val linLay: LinearLayout get() = findViewById(R.id.Linearlayout)
  
      var listaFlipper: ArrayList&lt;String&gt; = ArrayList()
  
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_flipper_list)
  
  
  
  
  
  
          /*    listaFlipper.clear();
              listaFlipper.add(passaFlintstones.text.toString())
              listaFlipper.add(bottone2.text.toString())
              listaFlipper.add(bottone3.text.toString())*/
  
              searchbar.isSubmitButtonEnabled=true
  
  
  
  
             searchbar.setOnQueryTextListener() {
  
                   fun onQueryTextChange(newText: String?): Boolean {
                      filter(newText)
                      return true
                  }
  
                   fun onQueryTextSubmit(query: String?): Boolean {
                      filter(query)
                      return true
                  }
  
                      // Do your task here
  
  
                  }
  
  
          passaFlintstones.setOnClickListener()
          {
              val intent = Intent(this, FlintstonesScheda::class.java)
              //avvia registrazione
              startActivity(intent)
              // finish()
          }
  
      }
  
      fun filter(searchText: String?) {
          for (i in 0 until linLay.childCount) {
              val button: Button = linLay.getChildAt(i) as Button
              if (button.text.toString().contains(searchText!!)) {
                  button.isVisible=true
              } else button.isVisible=false
          }
      }
  
  
      private fun SearchView.setOnQueryTextListener(function: () -&gt; Unit) {
  
      }
  }
  </code></pre>
  <p>As you can see I'm not even near to a solution, I hope you can help! Thank you!</p>