2012-03-07 15 views
0

我正在編輯我的帳戶的屏幕。選擇適當的價值的微調accroding我的類

我的帳戶類有一些屬性。現在我想顯示這些屬性,然後編輯它們。 我做了一個顯示賬戶類型的微調。

現在我使用此代碼

ArrayAdapter<CharSequence> typeOfAccountAdapter = ArrayAdapter.createFromResource(
         this, R.array.typeOfAccountArray, android.R.layout.simple_spinner_item); 
       adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
       typeOfAccount.setAdapter(typeOfAccountAdapter); 

       typeOfAccount.setOnItemSelectedListener(new OnItemSelectedListener() 
       { 
        @Override 
        public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) 
        { 
         if (typeOfAccount.getSelectedItem().toString().equals("Income")) 
          myAccount.accountType = AccountType.kAccountTypeIncome; 
         else if(typeOfAccount.getSelectedItem().toString().equals("Asset")) 
          myAccount.accountType = AccountType.kAccountTypeAsset; 
         else if(typeOfAccount.getSelectedItem().toString().equals("Cash")) 
          myAccount.accountType = AccountType.kAccountTypeAssetCash; 
         else if(typeOfAccount.getSelectedItem().toString().equals("Bank")) 
          myAccount.accountType = AccountType.kAccountTypeAssetBank; 
         else if(typeOfAccount.getSelectedItem().toString().equals("Liability")) 
          myAccount.accountType = AccountType.kAccountTypeLiability; 
         else 
          myAccount.accountType = AccountType.kAccountTypeLiabilityOther; 
         setStrDeatilOfAccount(); 
        } 

這段代碼實際上而不是顯示myAccount.accountType,套spinner第一元素作爲我的賬戶accountType

我怎樣才能不顯示的typeOfAccountArray數組的第一個項目但myAccount

accountType,然後我可以編輯,並相應地改變它。

問候

回答

0
String yourAccountTypeInString; 
       if (myAccount.accountType == yourAccountType) 
        yourAccountTypeInString= "theStringOfAccountType"; 
     // use else if 

       int pos = typeOfAccountAdapter.getPosition(yourAccountTypeInString); 
       typeOfAccount.setSelection(pos); 

試試這個,告訴

0
typeOfAccount.setOnItemSelectedListener(new OnItemSelectedListener() 
      { 
       @Override 
       public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) 
       { 
     constants_class.GROUP=(String) typeOfAccountAdapter.getItem(arg2).toString(); 
     if(constants_class.GROUP.equalsIgnoreCase("Income")){ 

     } 
     else if(constants_class.GROUP.equalsIgnoreCase("Asset")){ 

     } 
     else if(constants_class.GROUP.equalsIgnoreCase("Asset")){ 

     } 
}}); 

和默認微調採取的第一個值,但是當你點擊微調並選擇任何項目將採取correct..Hope這將對你有幫助