2012-09-06 24 views
-1

您好,我有一個開發我app..here都在我的mysql數據庫中更新了我的微調值..微調值動態變化取決於數據庫

爲如:status ....在這裏,我要運行應用程序第一次總是隻顯示Q. ..我必須更新狀態Q後,我必須運行應用程序意味着自動顯示狀態C ....我怎麼能發展this.Why總是顯示Q .. 。我可以在這裏管理代碼。 這裏我使用了下面的代碼。

private void createSpinnerDropDown() { 

    //get reference to the spinner from the XML layout 
    Spinner spinner = (Spinner) findViewById(R.id.spinner1); 

    //Array list of animals to display in the spinner 
    List<String> list = new ArrayList<String>(); 

    list.add("Q"); 
    list.add("P"); 
    list.add("F"); 
    list.add("I"); 
    list.add("C"); 

    //create an ArrayAdaptar from the String Array 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
      android.R.layout.simple_spinner_item, list); 
    //set the view for the Drop down list 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    //set the ArrayAdapter to the spinner 
    spinner.setAdapter(adapter); 
    adapter.notifyDataSetChanged(); 
    //attach the listener to the spinner 
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener()); 

} 

我該如何開發這個。

+0

我不清楚你想保存選擇的項目到數據庫或想要顯示保存的項目在數據庫到微調? – Ishtiaq

+0

我的數據庫的狀態是C意味着我想顯示我的微調也顯示C ...但在我的代碼Q只顯示在微調總是... –

+0

在這裏我必須運行應用程序第一次總是顯示Q我的旋轉框..我必須更新狀態Q到C後,我必須運行應用程序意味着自動顯示狀態C ....我怎麼能發展this.Why總是顯示Q ...我如何管理代碼在這裏。 –

回答

0
if(list.contains(DATABASE.FETCH())) 
    spinner.setSelection(list.indexOf(DATABASE.FETCH())); 

DATABASE.FETCH()是您從數據庫中獲取數據(C)的方法。

0

我不知道它會正是你想要。如何我設法這一點,而不是保存所選的項目只得到selectedItemPosition

int selectedIndex = spinner.getSelectedItemPosition(); 

,當你想從數據的基礎上設定的微調項,剛取指數,讓說

int SavedIndex = FetchSavedSpinnerIndex(); 

立刻設置微調的項目,作爲

spinner.setSelection(SavedIndex);