I want to use spinner prompt like "Select City". I did set a value for select_city
in string layout use in layout android:prompt="@string/select_city"
but it did not work. Also tried to use sp_city.setPrompt("Select City");
also did not work.
What is my problem? How can I fix it and set the prompt?
Layout:
<Spinner
android:id="@+id/spinner_poi_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown"/>
Class:
public class FirstPOIPreference extends DialogPreference {
private Spinner sp_city;
private ArrayAdapter<String> adapter;
private POI poiDialog = new POI();
public FirstPOIPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setPersistent(false);
setDialogLayoutResource(R.layout.pref_poi_dialog);
setPositiveButtonText(android.R.string.ok);
setNegativeButtonText(android.R.string.cancel);
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
initViews(view);
}
private void initViews(View view) {
sp_city = (Spinner) view.findViewById(R.id.spinner_poi_city);
sp_city.setPrompt("City");
String[] arrayCity = new String[]{"Erie", "Pittsburgh", "Cleveland", "Buffalo", "Niagara Falls", "Jamestown"};
adapter = new ArrayAdapter <> (this.getContext(), android.R.layout.simple_spinner_dropdown_item, arrayCity);
sp_city.setAdapter(adapter);
sp_city.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView <?> parentView, View selectedItemView, int position, long id) {
poiDialog.setCity(sp_city.getSelectedItem().toString());
}
@Override
public void onNothingSelected(AdapterView <?> parentView) {
}
});
}
}