1

I have 2 AutoCompleteTextView with 2 onTouchListener, the problem is that, when I enter the first time in the activity, the touch listener triggered before touch the something in my activity..

Does anyone know the reason?? Is there a solution to not triggered it the first time I enter in activity?

EDIT

I have the same problem with OnItemSelectedListener on a spinner, what can i do?? This is my listener:

country.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            filter();
        }
    });

Thanks in advance

Teo
  • 3,143
  • 2
  • 29
  • 59
  • hi please check the answer and make sure what position you are getting when the listener auto-fires. – Parvaz Bhaskar Sep 20 '13 at 06:55
  • 1
    I have the same problem on a Sansui LifeTab/ETab 704VP running Android 4.0.4. The boolean thing is annoying but seems like the simplest solution. – Engineer Aug 13 '15 at 21:49

1 Answers1

1

Are you sure you are filtering your touch events like below?

image.setOnTouchListener(new OnTouchListener() {            
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN){

            }else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL){

            }               


       return true;
        }
    });

Refer this link also.

Edit: Place a log and check what is the value of int position when the onItemClickListener is fired automatically.I would recommend you to keep your spinner's 0 position empty and to place a check for if position is zero then ignore and else do the filter.

country.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position == 0)

{
//do nothing
}
else
{
filter();
}            

        }
    });
Community
  • 1
  • 1
Parvaz Bhaskar
  • 1,367
  • 9
  • 29
  • Yes, I filtered with action down.. and I resolved it, but now the event onItemSelected on Spinner does the same thing: when i enter the first time in the activity it triggers the listener. How can I solve it? – Teo Sep 20 '13 at 06:17
  • Can you post the code for this?meanwhile check the link in the updated answer – Parvaz Bhaskar Sep 20 '13 at 06:22
  • I solved it add a boolean variable.. the first time that I enter in the activity it is false, than it is true.. – Teo Sep 20 '13 at 07:05