1

我試圖讓微調選擇已使用Parse.com獲取微調選擇後Parse.com

這是我所得到的,當我使用 uniSpinner.getSelectedItem().toString(); 充滿後動態加油吧這是我得到:

[email protected]"Some numbers here, not the ID stored in parse" 

下面的代碼也產生同樣的結果:

Toast.makeText(parent.getContext(), "test: " + 
      parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show(); 

這是我第代碼在創造微調:

public void uniSpinnerSetup() 
{ 
    ParseQueryAdapter.QueryFactory<ParseObject> factory = new ParseQueryAdapter.QueryFactory<ParseObject>() { 
     public ParseQuery create() { 
      ParseQuery query = new ParseQuery("University"); 
      return query; 
     } 
    }; 

    uniSpinner = (Spinner) findViewById(R.id.uniSpinner); 

    ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(this, factory); 
    adapter.setTextKey("name"); 
    uniSpinner.setAdapter(adapter); 
    uniSpinner.setSelection(1); 
    uniSpinner.setOnItemSelectedListener(new mySpinnerListener()); 
} 

class mySpinnerListener implements Spinner.OnItemSelectedListener 
{ 
    @Override 
    public void onItemSelected(AdapterView parent, View v, int position,long id) { 
     // TODO Auto-generated method stub 
     Toast.makeText(parent.getContext(), "test: " + 
       parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show(); 

    } 

    @Override 
    public void onNothingSelected(AdapterView parent) { 
     // TODO Auto-generated method stub 
     // Do nothing. 
    } 

} 

我看上去很高和低嘗試和解決它,還沒有找到解決方案!請幫忙嗎?

回答

1

(正確答案是在評論部分)

了移動適配器作爲一個字段變量,使用讓您的對象:

ParseQueryAdapter<ParseObject> adapter; 

public void uniSpinnerSetup() 
{ 
    ParseQueryAdapter.QueryFactory<ParseObject> factory = new ParseQueryAdapter.QueryFactory<ParseObject>() { 
     public ParseQuery create() { 
      ParseQuery query = new ParseQuery("University"); 
      return query; 
     } 
    }; 

    uniSpinner = (Spinner) findViewById(R.id.uniSpinner); 

    adapter = new ParseQueryAdapter<ParseObject>(this, factory); 
    adapter.setTextKey("name"); 
    uniSpinner.setAdapter(adapter); 
    uniSpinner.setSelection(1); 
    uniSpinner.setOnItemSelectedListener(new mySpinnerListener()); 
} 

class mySpinnerListener implements Spinner.OnItemSelectedListener 
{ 
    @Override 
    public void onItemSelected(AdapterView parent, View v, int position,long id) { 
     // TODO Auto-generated method stub 
     ParseObject theSelectedObject = adapter.getItem(position); 
     Toast.makeText(parent.getContext(), "test: " + 
       theSelectedObject.toString(), Toast.LENGTH_LONG).show(); 

    } 

    @Override 
    public void onNothingSelected(AdapterView parent) { 
     // TODO Auto-generated method stub 
     // Do nothing. 
    } 

} 
+0

產生完全相同的結果:'com.parse。 ParseObject @「這裏有一些數字,而不是存儲在解析中的ID」' – dominicE 2015-04-05 23:25:29

+0

好的,那麼也許這個改變是不需要的。如果你這樣做,會發生什麼情況:「toSelectedObject.getObjectId()'或'selectedObject .get(」name「)'在吐司? – cYrixmorten 2015-04-05 23:27:01

+0

哦,我非常感謝你!這實際上完全符合我的要求,並獲得大學的名稱,而不是參考(或不管它是什麼)。再次感謝:) – dominicE 2015-04-05 23:31:00