当我从微调器中选择任何项目时,未设置任何文本。可能是什么错误?
ArrayAdapter<String> pSelectAdapter = new ArrayAdapter<String>(PCreate.this,android.R.layout.simple_spinner_item, pNames);
pSelectAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
selectP.setAdapter(pSelectAdapter);
selectP.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String nameSelected = pNames.get(arg2);
pID = pMatch.get(nameSelected);
p.setText(nameSelected);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
最佳答案
我认为在这里您错过了创建View类的对象的权限,请将此行与您的代码匹配,并进行此更改,这可能会对您有所帮助。
selectP.setOnItemSelectedListener(new View.OnItemSelectedListener() {
(new View.OnItemSelectedListener() instaed (new OnItemSelectedListener()