I have an AutoCompleteTextView that will show a list of Hints when type in few keyword that match with its ArrayAdapter Data.
Currently, I have set an AdapterView.OnItemClickListener so when user click on the Hint, the soft keyboard on screen will be close.
What I trying to achieve :
- 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 add another ClickListener for the AdapterView such as LongClickListener, so when user LongClick on the Hint, it will trigger a Dialog Pop Out and prompt the Delete Confirmation from the User.
I been search for how to set LongClickListener on Autocomplete, however I could not find any solution on the net.
I believe it is important to ensure the Click Listen able to obtain the position(in Int) or text data(in String) 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.
My Questions:
How can I set a Long Click Listener for the AutoCompleteTextView that will also obtain the selected Hint position?
Any other solution that could help to resolve what I trying to achieve is welcome, thank you.
Note: I would like to keep the functionality of the hide soft keyboard when Hint is selected. I accept Answer In Java Language as well.
What I have done so far :
// Get an ArrayList<String> from database and declare to remarkList
val remarkList: ArrayList<String> = 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<ArrayAdapter<String>>(adapter)
// When click the hint selection, will trigger close keyboard function
autoComplete_remarks.onItemClickListener =
AdapterView.OnItemClickListener { _: AdapterView<*>, _: View, position: Int, _: Long ->
hideKeyboard(activity!!)
}