如何禁用我的活动中显示的并排DatePicker(在KitKat/ Android 4.4
下运行,我使用Sony Xperia
运行它),我一直在努力寻找这一个,左侧包含滚动部分,右侧包含完整日历,我只想显示完整的日历:
import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.TextView;
public class versi2 extends Activity {
private TextView textViewTanggal;
private DatePicker datePicker;
private int year;
private int month;
private int day;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.versi2);
setCurrentDateOnView();
}
// display current date
public void setCurrentDateOnView() {
textViewTanggal = (TextView) findViewById(R.id.tvDisplayDate);
datePicker = (DatePicker) findViewById(R.id.dpResult);
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
// set current date into textview
textViewTanggal.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(month + 1).append("-").append(day).append("-")
.append(year).append(" "));
datePicker.init(year, month, day, dateSetListener);
}
private DatePicker.OnDateChangedListener dateSetListener = new DatePicker.OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
textViewTanggal.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(dayOfMonth + 1).append("-").append(monthOfYear).append("-")
.append(year).append(" "));
}
};
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
....
....
<DatePicker
android:id="@+id/dpResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>