我收到一个错误“MyDialogFragment 类型的方法 getParentFragment() 未定义”
我不确定为什么会出现此错误,就我而言,我已经正确设置了所有内容。
任何指导都会有所帮助,谢谢。
import android.app.DialogFragment;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
class MyDialogFragment extends DialogFragment {
private Button ButtonOk;
private Button ButtonCancel;
public MyDialogFragment() {
// Empty constructor required for DialogFragment
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.prompt, container);
ButtonOk = (Button) view.findViewById(R.id.button1);
ButtonCancel = (Button) view.findViewById(R.id.button2);
getDialog().setTitle("Set Wallpaper?");
ButtonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Here
((ImageDetailFragment)(MyDialogFragment.this.getParentFragment())).onDialogOKPressed();
dismiss();
}
});
ButtonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
MyDialogFragment.this.dismiss();
}
});
return view;
}
}
从我的主要片段导入:
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;