Android - CheckedChangeListener在以编程方式检查radiobutton(在radiogroup内部)

时间:2016-02-02 06:05:20

标签: android radio-button radio-group

我有一个活动,我根据radiobutton(内部放射组)的检查状态隐藏/取消隐藏一些布局和视图。 但是当我以编程方式检查radiobutton时,checkedchangelistener无效。但是当我手动检查radiobutton时工作正常。 这是我的checkedChangeListener: ll - LinearLayout edt - EditText

rg_listing.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()

                                          {
                                              @Override
                                              public void onCheckedChanged(RadioGroup group, int checkedId) {
                                                  switch (checkedId) {
                                                      case R.id.rb_auction:
                                                          listing_type = "auction";
                                                          ll_ps.setVisibility(View.GONE);
                                                          edt_startB.setVisibility(View.VISIBLE);
                                                          edt_resP.setVisibility(View.VISIBLE);
                                                          btn_startB.setVisibility(View.VISIBLE);
                                                          btn_resP.setVisibility(View.VISIBLE);
                                                          break;
                                                      case R.id.rb_fixedprice:
                                                          listing_type = "fixed price";
                                                          ll_ps.setVisibility(View.GONE);
                                                          edt_startB.setVisibility(View.GONE);
                                                          edt_resP.setVisibility(View.GONE);
                                                          btn_startB.setVisibility(View.GONE);
                                                          btn_resP.setVisibility(View.GONE);
                                                          break;
                                                      case R.id.rb_privatesale:
                                                          listing_type = "private sale";
                                                          ll_ps.setVisibility(View.VISIBLE);
                                                          edt_startB.setVisibility(View.GONE);
                                                          edt_resP.setVisibility(View.GONE);
                                                          btn_startB.setVisibility(View.GONE);
                                                          btn_resP.setVisibility(View.GONE);
                                                          break;
                                                      default:
                                                          System.out.println("Error in switch");
                                                          break;
                                                  }
                                              }
                                          }

    );

我已尝试radiobutton.performClick()radiobutton.setChecked()radiogroup.check() ...

非常感谢任何帮助...... !!!

0 个答案:

没有答案