当我的应用程序中的菜单项打开datePicker并选择一个日期时,仅当我再次打开选项菜单时,UI中的textview'selectedDateView'才会更新。菜单操作完成后更新活动UI
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
DialogFragment newFragment = new SettingsDatePicker();
newFragment.show(getFragmentManager(), "Select the date");
// i think this is called only the second time
selectedDateView.setText(String.format("Selected Date: %s", settings.getConfiguredDateTime().toString(fmt)));
return true;
}
return super.onOptionsItemSelected(item);
}
有没有办法来重写OnSettingMenuItemFinished或类似的东西?
感谢您的帮助。
在你的dialogfragment中有一个回调,然后当你选择日期时调用回调。例如:[链接](http://stackoverflow.com/questions/9776088/get-data-back-from-a-fragment-dialog-best-practices) – mario
活动布局中的'selectedDateView'。你可以发布布局吗? – Libin
谢谢@mario 我使用你的建议解决了这个问题:D – BinaryFr3ak