我正在尝试在微调器上使用这个适配器,它给出了空指针异常,请给你有价值的回应
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, R.array.select_action_arrays);
在我的 string.xml 文件中
<string-array name="select_action_arrays">
<item>alert1</item>
<item>alert2</item>
<item>alert3</item>
<item>alert4</item>
<item>alert5</item>
</string-array>
这是完整的代码行
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.select_action_arrays));
spinnerSelectAction.setAdapter(adapter);
spinnerSelectAction = (Spinner)findViewById(R.id.spinnerSelectAction);
spinnerSelectAction.setAdapter(adapter);
spinnerSelectAction.setOnItemSelectedListener(new OnItemSelectedListener() {
int count=0;
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
if(count >= 1){
Toast.makeText(getBaseContext(),"inside on item selected ",Toast.LENGTH_SHORT).show();
}
count++;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {}
});
spinnerSelectAction 似乎已初始化