我试图在使用Parse.com
填充后调整微调器这是我使用时得到的
uniSpinner.getSelectedItem().toString();
这就是我得到的:
com.parse.ParseObject@"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.
}
}
我看起来很高低,试图解决它,还没有找到解决方案!有什么帮助吗?
答案 0 :(得分: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.
}
}