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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:50:29+00:00 2026-06-04T16:50:29+00:00

I have a spinner in my application that shows a location. Either your current

  • 0

I have a spinner in my application that shows a location. Either your current location or a location of your own choice that you have to enter. Or so it should You can find a great example of this is Google Places. That is what I want to achieve, more or less…

So if the app is first created, I fetch the current location of the user and set the location-property of my custom arrayadapter to the location. After that, I refresh the drawablestate. In the getView of my Adapter, I change the text to white and set the text to the location property. This works fine.

When I choose for a different location, I get an input dialog to enter my location. Once done, I update the location property of my adapter and make the spinner refresh it’s drawableState. After doing that, I enter my getView function in the adapter again, edit the text’s color and the text itself, but the text in the spinner remains the same. Only after I hit the spinner again and hit ‘current location’, it shows the location I gave it earlier. If I hit ‘current location’ again, it does nothing (it fetches the location, but doesn’t update the view). When I proceed to hit ‘another location’ again, it shows your current location and asks for the other location and it’s the same all over again.

Does anybody have an idea of how to solve this? See below for my code:

public class FooActivity extends Activity {

//UI-elements
private Spinner _locationSpinner;
private LocationArrayAdapter _locationAdapter;

//Location
private String[] _locationArray = {"Current location", "Different location"};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //config spinner
    configSpinner();
}
//functions
private void configSpinner() {
    _locationSpinner = (Spinner)findViewById(R.id.main_location);

    _locationAdapter = new LocationArrayAdapter(this, R.layout.spinner_item, _locationArray);
    _locationAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);

    showCurrentLocationInSpinner();
    _locationSpinner.setAdapter(_locationAdapter);
    _locationSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            if (pos == 0)
                showCurrentLocationInSpinner();
            else
                showOtherLocationInSpinner();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {}

    });
}

//view functions
private void showCurrentLocationInSpinner() {
    try {
        Location loc = getCurrentLocation();
        if (loc == null) return;

        List<Address> addresses = _geo.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
        Address curAddress = addresses.get(0);

        _locationAdapter.setLocation(curAddress.getAddressLine(0) + ", " + curAddress.getLocality());
        _locationSpinner.refreshDrawableState();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IndexOutOfBoundsException e){
        e.printStackTrace();
    }
}
protected void showOtherLocationInSpinner() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setMessage(getResources().getString(R.string.location_dialog_message));

    // Set an EditText view to get user input 
    final EditText input = new EditText(this);
    alert.setView(input);

    alert.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
        Editable value = input.getText();
        _locationAdapter.setLocation(value.toString());
        _locationSpinner.refreshDrawableState();
      }
    });

    alert.setNegativeButton(getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
      }
    });

    alert.show();
}
}

My custom ArrayAdapter:

public class LocationArrayAdapter extends ArrayAdapter<CharSequence> {

private String _location;

public LocationArrayAdapter(Context context, int textViewResourceId, CharSequence[] objects) {
    super(context, textViewResourceId, objects);
}

public String getLocation() {
    return _location;
}
public void setLocation(String location) {
    this._location = location;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);

    TextView t = (TextView) view.findViewById(android.R.id.text1);
    t.setTextColor(Color.WHITE);
    t.setText(_location);

    return view;
}

}
  • 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-04T16:50:30+00:00Added an answer on June 4, 2026 at 4:50 pm

    Turns out to be quite the stupid mistake… I just had to notify my Adapter that the dataset had changed…

    public class LocationArrayAdapter extends ArrayAdapter<CharSequence> {
    
        private String _location;
    
        public LocationArrayAdapter(Context context, int textViewResourceId, CharSequence[] objects){
            super(context, textViewResourceId, objects);
        }
    
        public String getLocation() {
            return _location;
        }
        public void setLocation(String location) {
            this._location = location;
            notifyDataSetChanged(); //FIXES IT
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
    
            TextView t = (TextView) view.findViewById(android.R.id.text1);
            t.setTextColor(Color.WHITE);
            t.setText(_location);
    
            return view;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple function that shows loading spinner while fetching data (usually takes
I have an application, which has a Spinner that I want populated with some
in may application, i have a spinner widget that contains huge amount of data.
I have one problem in my application. the problem is that can i bind
I have created an application for ContactsContract... I have created a spinner which brings
Hi I have a spinner (spinner5) and whenever the user selects an item that
I have within a TabActivity a Spinner that will be generated dynamically. Just to
I have an application that is an NSStatusItem . It has a few different
I have a AS spinner class that I downloaded from Jake Hawkes ( click
I am trying to make an application that will have a set of screens

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.