我正在开发一个Android应用程序,可以从Web服务获取数据并将其加载到下拉列表中。我需要在跳转到其他页面并返回时维护所选数据的状态。例如,如果我从Web服务获取数据为
我的代码:
在
1.apple 2.orange 3.grapes
并将其加载到下拉列表中,然后我选择orange
。当我跳转到其他屏幕并返回时,所选的下拉列表数据应该是orange
。但它会再次从服务器加载数据到下拉列表中。有人能帮我解决这个问题吗?我的代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
if (Constants.SPINNER != null ) {
spinner.setSelection( Constants.SPINNER);
} else {
//WebCall here for getting data
}
//...
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent,
View view, int arg2, long arg3) {
Constants.SPINNER = spinner.getSelectedItemPosition();
在
Constant
类中:public static Integer SPINNER="";