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 6924957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:43:42+00:00 2026-05-27T10:43:42+00:00

I only wan’t the user to be able to click on a button if

  • 0

I only wan’t the user to be able to click on a button if they have pressed a suggestion from my autocompleteTextview.

To accomplish this, i implemented an onKeyListener im my adapter and removed the tag which was set by the adapter if you pressed a suggestion. Then i checked if there was tag.

But the onKeyListener does not seem to remove the tag properly:

public class StopCursorAdapter extends CursorAdapter{

    private Context context;
    private LayoutInflater inflater;
    private AutoCompleteTextView autoCompleteTextView;

    public StopCursorAdapter(final AutoCompleteTextView autoCompleteTextView, Context context, Cursor c){
        super(context, c);
        this.context = context;
        this.autoCompleteTextView = autoCompleteTextView;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        this.autoCompleteTextView.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event){
                StopCursorAdapter.this.autoCompleteTextView.setTag(null);
                Log.d("cursor", "Removed tag");
                Log.d("cursor", String.valueOf(StopCursorAdapter.this.autoCompleteTextView.getTag() == null));
                Log.d("cursor", String.valueOf(autoCompleteTextView.getTag() == null));         
                return false;
            }
        });
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent){
        View v = inflater.inflate(android.R.layout.two_line_list_item, null);
        return v;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor){
        TextView txt1 = (TextView) view.findViewById(android.R.id.text1);
        TextView txt2 = (TextView) view.findViewById(android.R.id.text2);

        txt1.setTextColor(Color.BLACK);
        txt1.setText(cursor.getString(2));
        txt2.setText(cursor.getString(3));
    }

    @Override
    public CharSequence convertToString(Cursor cursor){
        autoCompleteTextView.setTag(new Stop(cursor.getString(1), cursor.getString(2), cursor
                .getString(3)));
        return cursor.getString(2);// + ", " + cursor.getString(3);
    }

    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint){
        Database.getInstance().ensureLoaded(context);
        String filter = "";
        if(constraint == null){
            filter = "";
        }else{
            filter = constraint.toString();
        }
        Cursor cursor = Database.getInstance().getStopsCursor(filter);
        return cursor;
    }
}

Is there any other way to solve this issue?

  • 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-05-27T10:43:42+00:00Added an answer on May 27, 2026 at 10:43 am

    Looking at your code:

    • setTag(new Stop(...)) is called from the adapter’s convertToString() method which will be called by the AutoCompleteTextView when it is building the selection list (for each row in the cursor) and also when it is performing the completion. I don’t think this is what you want.

    • setTag(null) is called from the listener’s OnKey() method which will be called when the user tap on the keyboard keys. I also don’t think this is correct.

    I think the correct code should be something similar to this instead:

        // set tag to non-null when key is pressed
        autoCompleteTextView.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                autoCompleteTextView.setTag(new Stop());
                return false;
            }
        });
    
        // set tag to null when an item is tapped
        autoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> p, View v, int pos, long id) {
                autoCompleteTextView.setTag(null);
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Details: Only disable after user clicks the submit button, but before the posting back
i have a website with polls , i want the user to be able
I wan't to load some data from my XML file using this function: public
I have several of this, where the only thing that differs is if its
The only experience I have so far with a touchscreen interface was one where
I only want a list of files that have been added (not ones that
Using only VBScript (launched from Windows Scripting Host) can I pull the DLL metadata
So i have a list and i wan to check is the view is
I'm trying to open another form with a button and it's only ok at
I'm serving requests from several XMLRPC clients over WAN. The thing works great for,

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.