在 android 中创建日期选择器时出现此错误 "Syntax error on tokens, AnnotationName expected instead"
public class Insert extends Activity {
private Header header;
private EditText etName;
private EditText etAge;
private TextView mDateDisplay;
private Button mPickDate;
private int mYear;
private int mMonth;
private int mDay;
static final int DATE_DIALOG_ID = 0;
private static final int ID_DATEPICKER = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.insert);
header = (Header) findViewById(R.id.layoutHeader);
header.init();
etName = (EditText) findViewById(R.id.et_name);
etAge = (EditText) findViewById(R.id.et_age);
Button datePickerButton = (Button)findViewById(R.id.pickDate);
datePickerButton.setOnClickListener(datePickerButtonOnClickListener);
}
private Button.OnClickListener datePickerButtonOnClickListener= new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
final Calendar c = Calendar.getInstance();
myYear = c.get(Calendar.YEAR);
myMonth = c.get(Calendar.MONTH);
myDay = c.get(Calendar.DAY_OF_MONTH);
showDialog(ID_DATEPICKER);
}
};
@Override
protected Dialog onCreateDialog(int id)
{
// TODO Auto-generated method stub
switch(id)
{
case ID_DATEPICKER:
Toast.makeText(Insert.this,"- onCreateDialog -",Toast.LENGTH_LONG).show();
int myYear;
int myMonth;
int myDay;
return new DatePickerDialog(this,myDateSetListener,myYear, myMonth, myDay);
default:
return null;
}
}
private DatePickerDialog.OnDateSetListener myDateSetListener = new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year,int monthOfYear, int dayOfMonth)
{
// TODO Auto-generated method stub
String date = "Year: " + String.valueOf(year) + "\n"+ "Month: " + String.valueOf(monthOfYear+1) + "\n"+ "Day: " + String.valueOf(dayOfMonth);
Toast.makeText(Insert.this, date,
Toast.LENGTH_LONG).show();
}
};
findViewById(R.id.btnInsert).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(Insert.this);
dbAdapter.openDataBase();
ContentValues initialValues = new ContentValues();
initialValues.put("name", etName.getText().toString());
initialValues.put("age", etAge.getText().toString());
long n = dbAdapter.insertRecordsInDB("user", null, initialValues);
Toast.makeText(Insert.this, "new row inserted with id = "+n, Toast.LENGTH_SHORT).show();
}
});
}
这是发生错误的代码。有人可以建议我如何消除此错误吗?