2013-04-05 2 views
0

datepicker에서 날짜를 가져오고 라디오 버튼 그룹에서 오두막 선택을해야하는 프로그램이 있습니다. 나는 내 잘못이 라디오 청취자에게 있다는 것을 알고있다. 아마도 나는 그것을 올바른 장소에 두지 않을 것이다. 나는 이것을 새로운 것을 명심하라 !! 감사!날짜 선택기가있는 RadioButton 선택

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); 

     } 

    }; 
} 
+0

참조 – Houcine

+0

아래의 대답은 귀하의 다른 질문에 대한 답변으로 100 % 아약스를 선택하는 것이 좋습니다. 'WebMethod'는 매우 쉽습니다. 당신은 단순히 jQuery'$ .ajax()'로 데이터를 보내고,'WebMethod'에서 처리하고, 데이터를 다시 클라이언트로 보냅니다. 그것은 훨씬 더 간단하고 논리적이며 (더 중요한 것은 기능적입니다.), 여러분 자신은 박스 안에 들어 가지 않을 것입니다. "가장 인기있는"여기를 클릭하면 좋은 자습서를 볼 수 있습니다. http://encosia.com/ –

답변

0

하여 오류 발생 PARAM checkedIdRadioGroup 내부 확인 RadioButton의 identifiant에 리퍼러, 그래서 당신의 코드는 다음과 같이 될 것입니다 (docs 참조) 때문이다 :

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

안녕하세요. 빠른 응답에 감사드립니다. 프로그램이 계속 중지됩니다. 나는 radiBasic과 radDeluxe를 btnBasic과 btnDeluxe 대신에 배치했는데, 이것들은 내 버튼의 ID입니다. – Lolo

+0

예외는 무엇입니까 ?? logcat에서 예외의 스택 추적을 추가하십시오. – Houcine

+0

귀하의 도움에 다시 한번 감사드립니다. 나는 개별 RadioButton에 대해 .isChecked를 변경하고 사용했으며 맨 아래의 OnDateSet 메서드에서 if 문을 사용했습니다. 정말 고마워!! – Lolo