下面的代码可以正常运行,但是我使用的时候会报错Toast.makeText(this,((TextView) view).getText().toString(), 2000).show();
不知道为什么。我尝试使用Toast.makeText(this.parent,((TextView) view).getText().toString(), 2000).show();
,它也会导致错误。
private void InitControl() {
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
nameList.toArray(new String[nameList.size()]));
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerFolder.setAdapter(adapter1);
spinnerFolder.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this,
((TextView) view).getText().toString(), 2000).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});