我有以下代码在单击按钮时创建一个事件。我想知道如何通过按下此按钮来创建多个(比如 5 个)事件。感谢您的任何帮助!
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Button button = (Button)findViewById(R.id.button1);
// button.setOnClickListener(this);
final CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox1);
final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
if (checkBox.isChecked()) {
{
SimpleDateFormat formatter = new SimpleDateFormat("MMMM dd, yyyy, h:mmaa");
long lnsTime = 0, lneTime = 0;
Date dateObject;
try{
String dob_var = "August 16, 2012, 11:35PM";
dateObject = formatter.parse(dob_var);
lnsTime = dateObject.getTime();
Log.e(null, Long.toString(lnsTime));
dob_var = "August 16, 2012, 11:59PM";
dateObject = formatter.parse(dob_var);
lneTime = dateObject.getTime();
Log.e(null, Long.toString(lneTime));
}
catch (java.text.ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
Log.i("E11111111111", e.toString());
}
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("title", "9:00AM Start");
intent.putExtra("description", "There will be a 9:00AM start tomorrow.");
intent.putExtra("eventLocation", "Chris' house");
intent.putExtra("beginTime", lnsTime);
intent.putExtra("endTime", lneTime);
startActivity(intent);
}
}
到目前为止,代码创建的单个事件很好,只是我需要创建多个,最好没有“保存/取消”屏幕。