0

datepicker から日付を取得し、ラジオ ボタン グループからキャビンの選択を取得する必要があるプログラムがあります。エラーがラジオボタンリスナーにあることはわかっています。おそらく、適切な場所に配置していません。私はこれが初めてであることを覚えておいてください!! ありがとう!

public class Main extends Activity {

    private int currentYear;
    private int currentMonth;
    private int currentDay;
    static final int DATE_DIALOG_ID = 0;
    private Button btDate;
    private TextView reservation;


    private String cabinChoice;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btDate = (Button)findViewById(R.id.btnDate);
        reservation = (TextView)findViewById(R.id.txtReservation);
        btDate.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
            showDialog(DATE_DIALOG_ID);                                      

            }           

        });
        //---RadioButton---
        RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup1);        
        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
        {
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                //---displays the ID of the RadioButton that is checked---
                switch(checkedId){
                case 0:
                    cabinChoice = "Basic";
                    break;
                case 1:
                    cabinChoice = "Deluxe";
                    break;
                }
            }
        });



        final Calendar c = Calendar.getInstance();
        currentYear = c.get(Calendar.YEAR);
        currentMonth = c.get(Calendar.MONTH);
        currentDay = c.get(Calendar.DAY_OF_MONTH);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    protected Dialog onCreateDialog(int id) {
        switch (id){
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this, reservationDate, currentYear, currentMonth, currentDay);

        }   

        return null;

    }
    private DatePickerDialog.OnDateSetListener reservationDate = new DatePickerDialog.OnDateSetListener(){

        @Override
        public void onDateSet(DatePicker view, int year, int month,
                int day) {
            // TODO Auto-generated method stub
            reservation.setText("Your reservation is set for " + (month + 1)+("-") + day + ("-") + year 
            + ("") + (" thru ") + ("") + (month + 1) + ("-") + (day + 2) + ("-") + year 
            + ("in") + cabinChoice);

        }

    };
}
4

1 に答える 1