當我的應用程序中的菜單項打開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