sai sai - 1 year ago 178
Android Question

how to set setOnClickListener for AutoCompleteTextView?

I am selecting text for AutoCompleteTextView.After i want apply setonclicklistener to selected text.if any have idea.

ArrayAdapter<String> arrAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, sampleACTV);
AutoCompleteTextView ACTV = (AutoCompleteTextView) findViewById(;

private static final String[] sampleACTV = new String[]
{ "android","","iphone","blackberry" };

in my example i am selecting one like
call an intent to go to nest Acitivity

Answer Source

There are different click listeners in AutoCompleteTextView.

The first way is in the layout xml, you can define the onCLick attribute, with the function that you want to be called, in the example below, clicked.

<AutoCompleteTextView xmlns:android=""
    android:onClick="clicked" />

Then, in your activity, you define the function clicked.

public void clicked(View v) { 
  // on click do ..

Or you can set it directly in your code:

ACTV.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {

If you want to set the click listener when the user clicks in an item in the dropdown list there is another method, the setOnItemClickListener.

ACTV.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
        //... your stuff

And you have a last option, to set the click listener when the user actually selects an item in the dropdown list using setOnItemSelectedListener.

ACTV.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    public void onItemSelected (AdapterView<?> parent, View view, int position, long id) {
        //... your stuff
    public void onNothingSelected (AdapterView<?> parent) {
        //... your stuff


Good luck!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download