我在程序中設置了一個spinner,但是選擇spinner的任何一項,都沒有文本出現。 錯誤出在哪裡呢?
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()