2012-10-10 56 views
1

我想我的應用程序填充一個空的textview與用戶從微調選擇的值。目前它似乎工作,但它只填充了我猜測的是整個遊標的textview:([email protected])。 有人可以幫我找出問題所在嗎?如有必要,我可以發佈更多代碼。Android - 從Spinner項目填充textview

// Set spinner listener to populate the description field onclick. 
    mContext = this; 
    commonDescSpin.setOnItemSelectedListener(new OnItemSelectedListener() { 
     public void onItemSelected(AdapterView<?> parent, View view, int position, long id){ 

      String stringItem = parent.getItemAtPosition(position).toString(); 
      mDescriptionText.setText(stringItem); 

     } 
     public void onNothingSelected(AdapterView<?> parent) {} 
     }); 

回答

3

試試這個:

// Set spinner listener to populate the description field onclick. 
    mContext = this; 
    commonDescSpin.setOnItemSelectedListener(new OnItemSelectedListener() { 
     public void onItemSelected(AdapterView<?> parent, View view, int position, long id){ 
       TextView objTextView = (TextView) commonDescSpin.getSelectedView(); 
      String stringItem = objTextView.getText().toString(); 
      mDescriptionText.setText(stringItem); 

     } 
     public void onNothingSelected(AdapterView<?> parent) {} 
     }); 
1

toString()方法通常具有其他與標​​識對象實例相關的實現。如果你知道,在微調的項目毫無疑問是一個字符串,你可以考慮進行顯式轉換:

String stringItem = (String)(spinner1.getItemAtPosition(2)); 
textViewStatus.setText(stringItem); 
相關問題