Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7992237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:30:18+00:00 2026-06-04T13:30:18+00:00

My question is very basic, as is my experience! Sorry about the length of

  • 0

My question is very basic, as is my experience! Sorry about the length of the post!

I am trying to create an AutoCompleteTextView with a listener so that I can do “stuff” when an item is selected.
The AutoCompleteTextView works fine, in so far as I can type in 2 characters and then select an item from the list which appears.
But the application never executes the listener code.

All my code, xml and log trace is here, so what is the simple piece that I am missing?
I’ve searched all the questions and it seems to be a common problem but none of the (very few) answers work for me.

Any help will be appreciated.

SOURCE

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

public class A_New_StartActivity extends Activity {

private final String LOG_TAG = "CJM";
private static String result = "No result";
private static final String[] myitems =  {
"Item 1",
"Item 2",
"Item 3",
"Item 4",
"Item 5"
};
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Log.d(LOG_TAG, "Entered onCreate");

    ArrayAdapter<String> itemAdapter = new ArrayAdapter<String>(this, R.layout.destination_item, myitems);
    AutoCompleteTextView itemView = (AutoCompleteTextView) findViewById(R.id.autocomplete_items);
    itemView.setAdapter(itemAdapter);

    itemView.setOnItemSelectedListener(new OnItemSelectedListener() { 
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 
            result = "Selected";
            Log.d(LOG_TAG, "Showing Result 1");
            TextView result_view = (TextView) findViewById(R.id.result_view); 
            result_view.setText(result);
            View scroll_visibility = findViewById(R.id.result_scroll); 
            scroll_visibility.setVisibility(View.VISIBLE); 
            View result_visibility = findViewById(R.id.result_view); 
            result_visibility.setVisibility(View.VISIBLE); 
        } 
        public void onNothingSelected(AdapterView<?> parent) { 
            Log.d(LOG_TAG, "In Nothing Selected");
            result = "Nothing";
            Log.d(LOG_TAG, "Showing Result 2");
            TextView result_view = (TextView) findViewById(R.id.result_view); 
            result_view.setText(result);
            View scroll_visibility = findViewById(R.id.result_scroll); 
            scroll_visibility.setVisibility(View.VISIBLE); 
            View result_visibility = findViewById(R.id.result_view); 
            result_visibility.setVisibility(View.VISIBLE); 
        }
    }); 
    Log.d(LOG_TAG, "completed onCreate");
}
}

MAIN.xml in R.layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp" >
</TextView>

<TextView 
    android:id="@+id/item_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text="@string/request_item"
    android:visibility="visible" />

<AutoCompleteTextView 
    android:id="@+id/autocomplete_items"
    android:completionThreshold="2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:visibility="visible" />

<ScrollView
    android:id="@+id/result_scroll"
    android:layout_width="220dp"
    android:layout_height="290dp"
    android:layout_marginTop="10dp" 
    android:layout_marginLeft="50dp"
    android:visibility="invisible" >

    <TextView
        android:id="@+id/result_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:maxLines="5"
        android:scrollbars="vertical"
        android:text="@string/result"
        android:visibility="invisible" />
</ScrollView>

<Button
    android:id="@+id/reset_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp" 
    android:layout_marginLeft="125dp"
    android:text="@string/button_text" />

DESTINATION_ITEM.xml in R.layout

<TextView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

STRINGS.xml in R.values

<resources>

<string name="app_name">A_New_Start</string>
<string name="request_item">Please enter the first 2 letters of the item</string>
<string name="result">Initialised</string>
<string name="button_text">OK</string>

LOG output

05-26 10:19:05.550: D/CJM(269): Entered onCreate

05-26 10:19:05.570: D/CJM(269): completed onCreate
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:30:19+00:00Added an answer on June 4, 2026 at 1:30 pm

    You are setting wrong Listener for AutoCompleteTextView. You have to set addTextChangedListener() and do the processing in the override methods of addTextChangedListener.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if this is a very basic question, but I am preparing to create
A very basic question... How can I only allow the selection of one option
Maybe my question is very basic, but regretfully I have very little experience with
guys I know this question is very basic but I've met in few publications
A very basic question in excel. I have a column with valid and with
A very basic question.. but I always do the bad implementation of this. I
Very basic question - but I couldn't find an answer. I have got a
Very basic question - how to get one value from a generator in Python?
This is very basic question from programming point of view but as I am
Very basic question- I've a xml file and I want to validate it against

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.