In my Application i am using Spinner which contain 1 to 60 items from which user have to select anyone of them.My problem is that when user again call the Activity which contain spinner, user can able to see his previously selected item as the default value of spinner.
I have try to use the spineer.setselection() but i am not able to get.
so if anyone have any ideal about this then please give some hint to solve my problem.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewGroup viewgroup = (ViewGroup) findViewById(R.id.myprofilelinear);
ViewGroup.inflate(this, R.layout.spinner,
viewgroup);
LoadUI();
}
public void LoadUI()
{
imgtoggle = (ImageView) findViewById(R.id.btntoggle);
imgtoggle.setOnClickListener(this);
String param=JsonDataProcessor.MYPROFILELIST.get(0).getIsTracking();
if(param.equalsIgnoreCase("True"))
{
imgtoggle.setImageResource(R.drawable.on_button);
}
else
{
imgtoggle.setImageResource(R.drawable.off_button);
}
btnsave = (Button)findViewById(R.id.btnSavechanges);
btnsave.setOnClickListener(this);
String[] s = new String[60];
int i;
for (i = 0; i < 60; i++) {
s[i] = Integer.toString(i+1);
}
spin = (Spinner) findViewById(R.id.TimeSpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(TimeSpin.this,
android.R.layout.simple_spinner_item, s);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(adapter);
}
You should Ignite OnItemselectedListener for this and set the selected value in Spinner
Check this Code :
spin_country is Spinner Object
first initialize the flag_default_country to false , then check for the String value selected by User that was stored in Some values. if the Array value at i’th position equals to the user selected value it will set the value at i in the Spinner.
For Saving the user selected value you can use the Shared preference.
Check this link for Shared Preference.
Let me know if you find any difficulty.