profilefragment это мой класс фрагмента, в котором я пытаюсь реализовать настраиваемое диалоговое окно
public class profileFragment extends Fragment implements
dialog.Dialoglistner {
String path;
Uri imageUri;
ImageView img;
ImageButton save;
private static final int PICK_IMAGE = 100;
TextInputEditText email, add, pswd, phone, name;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_profile,
container, false);
pswd = (TextInputEditText) view.findViewById(R.id.prof_pswd);
phone = (TextInputEditText) view.findViewById(R.id.prof_phone);
img = (ImageView) view.findViewById(R.id.profile);
save = (ImageButton) view.findViewById(R.id.save);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
savedata();
}
});
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGE);
}
});
pswd.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
//calling dialog class
dialog dialogbox = new dialog();
dialogbox.show(getActivity().getSupportFragmentManager(), "Custom Dialog");
}
});
return view;
}
@Override
public void applyText(String s1, String s2) {
pswd.setText(s2);
}
}
Класс диалога
public class dialog extends AppCompatDialogFragment {
private Dialoglistner Listner;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final EditText old, newpass, repass;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_layout, null);
old = (EditText) view.findViewById(R.id.OldPass);
newpass = (EditText) view.findViewById(R.id.NewPass);
repass = (EditText) view.findViewById(R.id.RePass);
builder.setView(view)
.setTitle("Change Password")
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String s1, s2, s3;
s1 = old.getText().toString();
s2 = newpass.getText().toString();
s3 = repass.getText().toString();
if (s2.compareTo(s3) == 0) {
Listner.applyText(s1, s2);
Toast toast = Toast.makeText(getActivity(), "Password Updated", Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(getActivity(),
" Password did not match, please try again", Toast.LENGTH_SHORT);
toast.show();
}
}
});
return builder.create();
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
ошибка в этой строке
com.example.rachitshah.volunteer.Main2Activity не может быть приведен к com.example.rachitshah.volunteer.dialog $ Dialoglistner на com.example.rachitshah.volunteer.dialog.onAttach (dialog.java:70)
Listner = (Dialoglistner) контекст;}
public interface Dialoglistner {
void applyText(String s1, String s2);
}
}