title: How to Set Multiple Click Listener to AutoCompleteTextView in Android?
body: <p>I have an <strong>AutoCompleteTextView</strong> that will show a list of Hints when type in few keyword that match with its ArrayAdapter Data.</p>
  
  <p>Currently, I have set an <strong>AdapterView.OnItemClickListener</strong> so when user click on the Hint, the soft keyboard on screen will be close.</p>
  
  <p><strong>What I trying to achieve :</strong></p>
  
  <ul>
  <li>I would like to add a functionality that allow user to Delete the Data of the Hint from the Database, so I was thinking to <strong>add another ClickListener for the AdapterView</strong> such as <strong>LongClickListener</strong>, so when user LongClick on the Hint, it will trigger a Dialog Pop Out and prompt the Delete Confirmation from the User. </li>
  </ul>
  
  <p>I been search for how to set LongClickListener on Autocomplete, however I could not find any solution on the net.</p>
  
  <p>I believe it is important to ensure the <strong>Click Listen</strong> able to obtain the <strong>position(in Int)</strong> or <strong>text data(in String)</strong> of the Hint as I would need to determine what are the Data that being selected and I can tell the Database to delete it.</p>
  
  <p><strong>My Questions:</strong></p>
  
  <p>How can I set a <strong>Long Click Listener</strong> for the AutoCompleteTextView that will also obtain the selected Hint position?</p>
  
  <p>Any other solution that could help to resolve what I trying to achieve is welcome, thank you.</p>
  
  <p><strong>Note:</strong> I would like to keep the functionality of the hide soft keyboard when Hint is selected. I accept <strong>Answer In Java Language</strong> as well.</p>
  
  <p><strong>What I have done so far :</strong></p>
  
  <pre><code> // Get an ArrayList&lt;String&gt; from database and declare to remarkList
   val remarkList: ArrayList&lt;String&gt; = getDataFromDatabase() 
  
   // Set remarkList Data into ArrayAdapter
   val adapter = ArrayAdapter(context!!, android.R.layout.simple_list_item_1, remarkList)
  
   // Set ArrayAdapter to AutoCompleteTextView
   autoComplete_remarks.setAdapter&lt;ArrayAdapter&lt;String&gt;&gt;(adapter)
  
          // When click the hint selection, will trigger close keyboard function
          autoComplete_remarks.onItemClickListener =
                  AdapterView.OnItemClickListener { _: AdapterView&lt;*&gt;, _: View, position: Int, _: Long -&gt;
  
                      hideKeyboard(activity!!)
                  }
  </code></pre>