错误:类型不兼容:PesoR_Male无法转换为上下文(AlertDialog自定义)

时间:2018-07-27 18:39:10

标签: android

错误是,错误:类型不兼容:PesoR_Male无法转换为上下文

我正在使用Tablayout,并且在布局中,我想显示一个自定义警报,该警报将在第33行和第40行中创建自定义警报时返回一个值,并给我一个错误:

 AlertDialog.Builder BLunes= new AlertDialog.Builder(PesoR_Male.this);

Toast toast= Toast.makeText(getApplicationContext(), "Toast", Toast.LENGTH_LONG);

这是一个解码代码:

public class PesoR_Male extends Fragment {
TextView lunes, martes, miercoles, jueves, viernes;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view= inflater.inflate(R.layout.pesor_male,container,false);

    lunes=view.findViewById(R.id.Lunes);
    martes=view.findViewById(R.id.Martes);
    miercoles=view.findViewById(R.id.Miercoles);
    jueves=view.findViewById(R.id.Jueves);
    viernes=view.findViewById(R.id.Viernes);

    lunes.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder BLunes= new AlertDialog.Builder(PesoR_Male.this);
            View mView= getLayoutInflater().inflate(R.layout.rutinas,null);

            ImageView img1= mView.findViewById(R.id.img1);
            img1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast toast= Toast.makeText(getApplicationContext(), "Toast", Toast.LENGTH_LONG);

                    toast.show();
                }
            });
            BLunes.setView(mView);
            AlertDialog dialog =BLunes.create();
            dialog.show();
        }
    });

    return view;
}

}

0 个答案:

没有答案