Java 缺少类日期选择器
我正在使用IntelliJ IDEA 11.1.2开发一个android应用程序,我需要在输入表单上使用datepicker。然而,当我插入它时,IDEA在预览窗口中给出“缺少类日期选择器”警告,我在手机上启动应用程序,它崩溃了。若删除datepicker元素,应用程序将正常工作 我使用android 2.2作为目标平台,java 1.6作为java SDK 以下是我表单的源代码:Java 缺少类日期选择器,java,android,datepicker,Java,Android,Datepicker,我正在使用IntelliJ IDEA 11.1.2开发一个android应用程序,我需要在输入表单上使用datepicker。然而,当我插入它时,IDEA在预览窗口中给出“缺少类日期选择器”警告,我在手机上启动应用程序,它崩溃了。若删除datepicker元素,应用程序将正常工作 我使用android 2.2作为目标平台,java 1.6作为java SDK 以下是我表单的源代码: <?xml version="1.0" encoding="utf-8"?> <LinearLa
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/l_main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="Some text: "
android:layout_width="fill_parent"
android:textSize="@dimen/fnt_size"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/source"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Some text: "
android:layout_width="fill_parent"
android:textSize="@dimen/fnt_size"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/destination"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="Some text: "
android:layout_width="fill_parent"
android:textSize="@dimen/fnt_size"
android:layout_height="wrap_content"
/>
<DatePicker
android:id="@+id/date"
android:endYear="2011"
android:startYear="2011"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/submitBtn"
android:text="Search"
android:layout_width="@dimen/btn_size"
android:textSize="@dimen/fnt_size"
android:layout_height="wrap_content" />
</LinearLayout>
我如何解决这个问题?更新:我对这个问题的看法(Android MAX\u YEAR){ datePicker.updateDate(最大年、月、月); } } }); } }
我不知道,但Eclipse最适合android开发。是否有使用Intelli J的特殊需要?没有特殊需要,但我觉得这个IDE最方便:)也非常清晰简洁地回答了编程解决方案。绝对是投票支持。
public class MyActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DatePicker datePicker = (DatePicker) findViewById(R.id.date);
final int MIN_YEAR = 2011;
final int MAX_YEAR = 2011;
datePicker.init(MIN_YEAR /* initial year */,
01 /* initial month of year */,
01 /* initial day of month */,
new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker datePicker,
int year,
int monthOfYear,
int dayOfMonth) {
// Override changing year to anything different from outside the range <MIN_YEAR, MAX_YEAR>
if (year < MIN_YEAR) {
datePicker.updateDate(MIN_YEAR, monthOfYear, dayOfMonth);
} else if (year > MAX_YEAR) {
datePicker.updateDate(MAX_YEAR, monthOfYear, dayOfMonth);
}
}
});
}
}