0

I asked a question here and got the answer

OK, all I needed was to add package name in xml file, so this spinner works now, but another problem has appeared. To select the element, that was selected during the initialise, I have to click on it twice. I guess, it is because I use a counter to check if the item selected by user:

variables.spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
                    @Override

                    public void onItemSelected(AdapterView<?> parent, View view,
                            int position, long id) {    
                        CharSequence t2 = (CharSequence) parent.getItemAtPosition(position);
                        variables.wall=t2.toString();
                        if(i>0){ 
                            new DownloadRow().execute();
                        }
                        if(i==0) i++;

                    }
                    @Override
                    public void onNothingSelected(AdapterView<?> arg0) 
                        // TODO Auto-generated method stub
                    }      
                });

What have I do to make it so that user will need to click on a selected item only once?

just a hint (i.e. you don't want any processing at all), no, this is an amiss variant. Situation is, when user clicks element at position 0 (or on any other position) new DownloadRow().execute() have to start. But now (I don't know why) if user clicks element at zero position, nothing happens. If he clicks it again DownloadRow().execute() starts, as it had to be done after the first user click. It looks like if during initialise of this spinner increament of var i doesn't happen (or some other problem). But if I do increament again if position==0. then DownloadRow().execute() starts automatically, user doesn't select an iem himself.

Community
  • 1
  • 1

2 Answers2

0

I'm not sure if I fully understand what you're trying to do here, but I think that if you change your if statement to be:

if(position>0){ 
    new DownloadRow().execute();
}

You should get the behaviour that you want, as this starts DownloadRow when an item other than the default value is selected.

If you need the default value selectable by the user, then I would suggest instead having the default value (at position 0) one which is just a hint (i.e. you don't want any processing at all), and every other position to be an option which you would like to call DownloadRow().execute

Matt Taylor
  • 3,360
  • 1
  • 20
  • 34
0

Found the solution.

 if(i==0) {
        if(position==0) variables.spinner1.setSelection(0);
        i++;
}