2011-03-23 46 views
0

我試圖將一個android微調選項中的值傳遞給一個url。我選擇的所有其他變量都會通過,並在微調器上顯示正確的微調器選項。 (在這裏,代碼不顯示所有變量)。Android微調工作正常 - 但無法解析並傳遞選定的值

我的日誌顯示國家VAR爲NULL。需要讓「country0」值像其他人那樣通過。我怎樣才能做到這一點?

感謝

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Log.d(DEBUG_TAG, "onCreate"); 
    mContext = this; //TODO legacy may not be needed 
    SERVER = this.getString(R.string.mygallerist_server_base); 
     settings = getSharedPreferences(PREFS_NAME, 0); 
     uid = settings.getString("uid", NOT_SET); 

     //SPINNER 
     Spinner spinner = (Spinner) findViewById(R.id.spinner); 
     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
       this, R.array.countries_array, android.R.layout.simple_spinner_item); 
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     spinner.setAdapter(adapter); 


     mOver35CheckBox = (CheckBox) findViewById(R.id.Over35); 
     class MyOnItemSelectedListener implements OnItemSelectedListener { 

       //SPINNER PARSING  
      @Override 
     public void onItemSelected(AdapterView<?> country0, 
       View view, int pos, long id) { 
      Toast.makeText(country0.getContext(), "The country is " + 
      country0.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show(); 

      } 

      @Override 
      public void onNothingSelected(AdapterView country0) { 
     // Do nothing. 

      } 

     } 

     spinner.setOnItemSelectedListener(new MyOnItemSelectedListener()); 
      final String country = country0;///MAYBE THIS IS WHAT IS WRONG 

     setPassword.setOnClickListener(new View.OnClickListener(){ 
      public void onClick(View v) { 
      // If all fields filled in then go to server 
       String country1 = country; /// OR MAYBE THIS IS WHAT IS WRONG 

      String userName = mUserNameEditText.getText().toString(); 

回答

1

也許我錯過了你的問題的東西,但是當你選擇了麪包的價值,你可以只設置一個私有成員的值,然後閱讀你的onClick這個值(如被你知道你在onItemSelected得到正確的值)

private String countrySelection; 
public void onItemSelected(AdapterView<?> country0, View view, int pos, long id) { 
     countrySelection = country0.getItemAtPosition(pos).toString(); 
     Toast.makeText(country0.getContext(), "The country is " + countrySelection, Toast.LENGTH_LONG).show(); 
} 
... 
final String country = countrySelection; 
setPassword.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v) { 
      sendDataToServer(country, ...); 

這是否解決您的問題?

編輯...

在這種情況下country0是什麼類型? (我還沒有評論權限)

final String country = country0;///MAYBE THIS IS WHAT IS WRONG 
+0

我剛剛寫了幾乎相同的建議。這幾乎是我在應用程序中處理Spinner的方式,它的工作原理完美無瑕。 – Klaus 2011-03-23 15:34:42

+0

國家值仍然是唯一一個來的NULL。嘗試了幾種不同的方式。這就是現在的情況:final String country1 = countrySelection; \t setPassword.setOnClickListener(新View.OnClickListener(){ \t \t公共無效的onClick(視圖v){ \t \t \t字符串username = mUserNameEditText.getText()的toString(); \t \t \t字符串userid = UID; \t \t \t字符串over_35 = 「」; 多個碼............ \t \t \t \t \t \t \t} \t \t \t別的 \t \t \t \t \t acctinfo(COUNTRY1,用戶名,email0,strPassword1,用戶類型,over_35,用戶id); – artworthy 2011-03-23 20:38:12

+1

好吧......不停地玩弄它並讓它起作用。謝謝! – artworthy 2011-03-23 21:10:22

相關問題