【发布时间】:2015-01-22 01:14:21
【问题描述】:
在我的应用程序中,我只想获取当前月份(不需要年份和日期)。例子。这个月是一月。显示来自 db 的与一月相关的列表视图数据。对于所有 12 个月。用户也可以从对话框中选择任何月份。我还在对话框中列出了月份来选择用户想要的月份。
问题
1. 获取当前月份,然后从 db 中填充数据(例如,当前月份是 1 月,然后从 db 中填充 1 月数据,如果当前月份是 4 月,则从数据中填充 4 月数据) 每个月。
问题
1. 如何知道当前月份?
2.如何填充与当月相关的数据?
当前代码:
public class MonthlyFragment extends Fragment {
private int monthField;
public MonthlyFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_monthly, container, false);
// String currentDateString = DateFormat.getDateInstance().format(new Date());
Button button = (Button) rootView.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showAlertDialog1();
}
});
return rootView;
}
private void showAlertDialog1() {
final String[] Selected = new String[]{"January", "February", "March", "April",
"May", "June", "July", "Augest", "September", "October", "November", "December"};
new AlertDialog.Builder(getActivity()).setTitle("Pick the month")
.setItems(Selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (Selected[which] == "January") {
// Show the
}
Toast.makeText(getActivity(), Selected[which], Toast.LENGTH_SHORT)
.show();
}
}).setNeutralButton("Close dialog", null).show();
}
}
谢谢,
【问题讨论】:
标签: android android-datepicker