我有一个像这样设置的ToggleButton:
final ToggleButton filterButton = (ToggleButton) findViewById(R.id.filterTags);
filterButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (filterButton.isChecked()) {
// pop up the list of tags so the user can choose which to filter by
// once one is chosen, the spinner will be updated appropriately
showDialog(DIALOG_TAGS);
} else {
// going unpressed, set the the spinner list to everything
updateSpinner(db.itemNames());
}
}
});
并且对话框看起来像:
case DIALOG_TAGS:
final String[] tagNames = db.tagNamesInUse();
dialog = new AlertDialog.Builder(this)
.setItems(tagNames, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
updateSpinner(db.getItemNamesForTag(tagNames[which]));
final ToggleButton filterButton = (ToggleButton) findViewById(R.id.filterTags);
filterButton.setTextOn(tagNames[which]);
dialog.dismiss();
}
})
.setNegativeButton("Cancel", UITools.getDialogCancellingListener())
.create();
如果ToggleButton被打开,它会弹出一个单选列表视图对话框,其中显示标签列表。选择标签后,它将成为ToggleButton的新textOn。如果ToggleButton被关闭(未选中),则文本回退到静态TextOff。问题是:对话框关闭后按钮没有被重绘。仍然显示先前textOn的值。
如何强制重新绘制?我尝试过filterButton.postInvalidate();但没有帮助。