目前我正在尝试获取日期(特别是月份和年份)并使用 TextView 显示它,但我的程序正在强制关闭。
这是我“得到”月份和年份的地方。
Calendar cCalendar = Calendar.getInstance();
int currentYear = cCalendar.get(Calendar.YEAR);
int currentMonth = cCalendar.get(Calendar.MONTH);
这是我设置 TextView 文本的地方。
public void setDateLabel(View v)
{
TextView month = (TextView)findViewById(R.id.monthLabel);
TextView year = (TextView)findViewById(R.id.yearLabel);
year.setText(currentYear);
month.setText(currentMonth);
}
这是带有 TextView 和 Button 的 XML。
<TextView android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/monthLabel"></TextView>
<TextView android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/yearLabel"></TextView>
<Button android:text="Button" android:onClick="setDateLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/setDate"></Button>
我尝试在 Debug 中运行它以获取 LogCat,但调试器只是停止并等待它在端口 8634 上“附加”。