我想填充一个位于Dialog中的微调器,但无法使上下文起作用。换句话说,我无法在ArrayAdapter中获得正确的上下文
这是代码
fab2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Create Add Bookamrk Dialog
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
View cView = getLayoutInflater().inflate(R.layout.dialog_addbookmark, null);
final EditText dTitle = (EditText)
//Declare all Textboxes, button and SPINNER
//Populate spinner
List<String> spinnerArray = new ArrayList<String>();
for (Category c: myCategories) {
spinnerArray.add(c.getName());
}
// I GET THE ERROR HERE ON THE CONTEXT
ArrayAdapter<String> adapter = new ArrayAdapter<String>(mBuilder.getContext(), android.R.layout.simple_spinner_dropdown_item, spinnerArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sItems.setAdapter(adapter);
//Create Click
cCreate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!dTitle.getText().toString().isEmpty() || !dURL.getText().toString().isEmpty() || !dCategory.getText().toString().isEmpty()) {
addBookmark(dTitle.getText().toString(), dURL.getText().toString(), dCategory.getText().toString());
} else {
Toast.makeText(MainActivity.this, "Please fill the Name", Toast.LENGTH_SHORT).show();
}
}
});
mBuilder.setView(cView);
AlertDialog dialog = mBuilder.create();
dialog.show();
}
});
该对话框是通过按一个按钮创建的,届时我希望填充微调器