DatePicker 的最小值 API
Minimum API for DatePicker
我只是测试了一个代码示例,以便在其他应用程序中实施,但我收到一条错误消息,指出使用 getInstance() 所需的最小 API 是 24,我我目前正在使用API 16。但是我在网上搜索过,似乎可以使用,因为API 1 O.o我可以忽略这个错误吗?
import android.app.DatePickerDialog;
import android.icu.util.Calendar;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
DatePickerDialog datePickerDialog;
EditText date;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
date = (EditText)findViewById(R.id.date);
date.setOnClickListener(new View.OnClickListener(){
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick(View v) {
final Calendar c;
c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
//Dialog DatePicker
datePickerDialog = new DatePickerDialog(MainActivity.this, new
DatePickerDialog.OnDateSetListener(){
@Override
public void onDateSet(DatePicker view,int year, int monthOfYear, int dayOfMonth){
date.setText(dayOfMonth + "/" +(monthOfYear + 1) + "/" + year);
}
},mYear,mMonth,mDay);
datePickerDialog.show();
}
});
}
}
替换:
import android.icu.util.Calendar;
与:
import java.util.Calendar;
我只是测试了一个代码示例,以便在其他应用程序中实施,但我收到一条错误消息,指出使用 getInstance() 所需的最小 API 是 24,我我目前正在使用API 16。但是我在网上搜索过,似乎可以使用,因为API 1 O.o我可以忽略这个错误吗?
import android.app.DatePickerDialog;
import android.icu.util.Calendar;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
DatePickerDialog datePickerDialog;
EditText date;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
date = (EditText)findViewById(R.id.date);
date.setOnClickListener(new View.OnClickListener(){
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick(View v) {
final Calendar c;
c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
//Dialog DatePicker
datePickerDialog = new DatePickerDialog(MainActivity.this, new
DatePickerDialog.OnDateSetListener(){
@Override
public void onDateSet(DatePicker view,int year, int monthOfYear, int dayOfMonth){
date.setText(dayOfMonth + "/" +(monthOfYear + 1) + "/" + year);
}
},mYear,mMonth,mDay);
datePickerDialog.show();
}
});
}
}
替换:
import android.icu.util.Calendar;
与:
import java.util.Calendar;