【问题标题】:Why setOnCheckedChangeListener not working in a popup that uses LayoutInflater?为什么 setOnCheckedChangeListener 在使用 LayoutInflater 的弹出窗口中不起作用?
【发布时间】:2013-02-20 06:50:58
【问题描述】:

我在弹出窗口中有一个 RadioGroup。当我放 setoncheckedchangelistener 时,它会导致错误。这是我的代码。该错误表示它不适用于参数(新的复合按钮。OnCheckedChangeListener ..我不明白有人可以帮助我吗?

   private void showPopupSeat(final Activity context) 
   {       
       int popupWidth = 500;
       int popupHeight = 650;


   // Inflate the popup_layout.xml
   LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popupseat);


   LayoutInflater layoutInflater = (LayoutInflater) context
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   View layout = layoutInflater.inflate(R.layout.seat_dimension, viewGroup);


  RadioGroup rg = (RadioGroup) layout.findViewById(R.id.rg1);
  final RadioButton rb1 = (RadioButton) layout.findViewById(R.id.option1);
  final RadioButton rb2 = (RadioButton) layout.findViewById(R.id.option2);
  final RadioButton rb3 = (RadioButton) layout.findViewById(R.id.option3);

      rg.setOnCheckedChangeListener(new OnCheckedChangeListener() 
      {
          public void onCheckedChanged(RadioGroup group, int checkedId) {

          }
  });


   final PopupWindow popupseat = new PopupWindow(context);
   popupseat.setContentView(layout);
   popupseat.setWidth(popupWidth);
   popupseat.setHeight(popupHeight);
   popupseat.setFocusable(true);


   // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
   int OFFSET_X = 30;
   int OFFSET_Y = 260;

     // Clear the default translucent background
   popupseat.setBackgroundDrawable(new BitmapDrawable());

   // Displaying the popup at the specified location, + offsets.
   popupseat.showAtLocation(layout, Gravity.CENTER, 0, 0);
  }

我不知道出了什么问题..请帮忙。

【问题讨论】:

    标签: android popup radio-group


    【解决方案1】:

    改为导入

    import android.widget.CompoundButton.OnCheckedChangeListener;

    导入

    import android.widget.RadioGroup.OnCheckedChangeListener;

    讨论了同样的问题here

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 2017-01-09
      相关资源
      最近更新 更多