如何显示从星期日到星期六的当前星期日期?我正在创建应用程序,当单击下周或前一周时显示当前星期日期显示下一个或上一个日期我的代码在所有 7 个按钮上显示相同的日期
public class MainActivity extends Activity {
public static int mYear;
public static int mMonth;
public static int mDay;
Button last_week;
Button next_week;
Button e00;
Button e01;
Button e02;
Button e03;
Button e04;
Button e05;
Button e06;
String completedate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e00 = (Button) findViewById(R.id.e00);
e01 = (Button) findViewById(R.id.e01);
e02 = (Button) findViewById(R.id.e02);
e03 = (Button) findViewById(R.id.e03);
e04 = (Button) findViewById(R.id.e04);
e05 = (Button) findViewById(R.id.e05);
e06 = (Button) findViewById(R.id.e06);
// e01 = Mon;
// e02 = Tues;
// e03 = Wed;
// e04 = thur;
// e05 = Fri;
last_week = (Button) findViewById(R.id.last_week);
next_week = (Button) findViewById(R.id.next_week);
Calendar mCalendar = Calendar.getInstance();
mYear = mCalendar.get(Calendar.YEAR);
mMonth = mCalendar.get(Calendar.MONTH) + 1;
mDay = mCalendar.get(Calendar.DAY_OF_MONTH);
completedate = mYear + "/" + String.format("%02d", mMonth)
+ "/" + String.format("%02d", mDay);
last_week.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
e00.setText("");
e01.setText("");
e02.setText("");
e03.setText("");
e04.setText("");
e05.setText("");
e06.setText("");
}
});
next_week.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
e00.setText("");
e01.setText("");
e02.setText("");
e03.setText("");
e04.setText("");
e05.setText("");
e06.setText("");
}
});
// i want to show like this
// e01.setText(" 9/9/2013");
// e02.setText("10/9/2013");
// e03.setText("11/9/2013");
// e04.setText("12/9/2013");
// e05.setText("13/9/2013");
DateFormat format = new SimpleDateFormat(completedate);
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.SUNDAY);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
String[] days = new String[7];
for (int i = 0; i < 7; i++)
{
days[i] = format.format(calendar.getTime());
e00.setText(days[0]);
e01.setText(days[1]);
e02.setText(days[2]);
e03.setText(days[3]);
e04.setText(days[4]);
e05.setText(days[5]);
e06.setText(days[6]);
}
}