无法进入onDateChanged方法..
package first.calculator.lihon.datepicker;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.TimePicker;
import java.util.Calendar;
public class MainActivity extends ActionBarActivity {
private TimePicker timePicker;
private DatePicker datePicker;
private Calendar calendar;
private int year;
private int month;
private int day;
private int hour;
private int minute;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取一个日历对象
calendar = Calendar.getInstance();
//获取年月日时分秒的信息
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH) + 1;
day = calendar.get(Calendar.DAY_OF_MONTH);
hour = calendar.get(Calendar.HOUR_OF_DAY);
minute = calendar.get(Calendar.MINUTE);
setTitle(year + "-" + month + "-" + day + "-" + hour + "-" + minute + "+111!");
datePicker = (DatePicker) findViewById(R.id.datePicker1);
timePicker = (TimePicker) findViewById(R.id.timePicker1);
;
//datepiceker初始化
datePicker.init(year, calendar.get(Calendar.MONTH), day, new OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// setTitle(year+"-"+monthOfYear+"-"+dayOfMonth+"+222!");
setTitle(year + "-" + monthOfYear + "-" + dayOfMonth + "+222!");
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="first.calculator.lihon.datepicker.MainActivity">
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/datePicker1"
android:layout_below="@+id/textView"
android:layout_alignParentStart="true"
android:layout_marginTop="134dp" />
<TimePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timePicker1" />
</LinearLayout>
请各位大大指点一下 谢谢了
我点击DatePicker无法更改标题(第二次setTitle那个地方)..