2012-03-07 43 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这将对你有帮助