1

ボタンがクリックされたときにイベントを作成する次のコードがあります。このボタンを押して、複数 (たとえば 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);

             }



    }

コードはこれまでのところ問題なく単一のイベントを作成します。できれば「保存/キャンセル」画面なしで、複数作成する必要があります。

4

1 に答える 1