它在活动中很容易,但在 DialogFragment 中我们做了更多的代码。
在 DialogFragment 类里面做你的 rutin findView ononActivityCreated
方法
btn_ocak = (Button) view.findViewById(R.id.btn_cal_ocak);
btn_subat = (Button) view.findViewById(R.id.btn_cal_subat);
btn_mart = (Button) view.findViewById(R.id.btn_cal_mart);
btn_nisan = (Button) view.findViewById(R.id.btn_cal_nisan);
btn_ocak.setOnClickListener(this);
btn_subat.setOnClickListener(this);
btn_mart.setOnClickListener(this);
btn_nisan.setOnClickListener(this);
将 onClick OnClickListener 实施到您的班级
public class CalendarPopUp extends DialogFragment implements View.OnClickListener
并在 onClick 方法中执行您想要的操作,通过执行这些操作,我们激活了视图的 onClick 事件
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_cal_ocak:
seciliAy = "Ocak";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_subat:
seciliAy = "Subat";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_mart:
seciliAy = "Mart";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_nisan:
seciliAy = "Nisan";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_mayis:
seciliAy = "Mayıs";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_haziran:
seciliAy = "Haziran";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_temmuz:
seciliAy = "Temmuz";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_agustos:
seciliAy = "Agustos";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_eylul:
seciliAy = "Eylül";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_ekim:
seciliAy = "Ekim";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_kasim:
seciliAy = "Kasım";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
case R.id.btn_cal_aralik:
seciliAy = "Aralık";
setMonthOnShare(seciliAy);
mCallback.onSelectedData(seciliAy);
dismiss();
break;
default:
break;
}
}
如果您想知道如何传递值,请按照这些步骤
clike_here