我陷入了看似简单的事情,但无法找到方法。我在片段中有一个方法和一个alertdialog。我想从alertdialog的onclickListener中调用该方法。
问题是,该方法无法从点击侦听器的侧面识别。我是否需要使用单独的DialogFragment和界面?没有创建额外的课程,有没有直接的方法?
public class myFragment extends Fragment {
public void samplefile(){
AlertDialog.Builder myDialog = new AlertDialog.Builder(getActivity());
myDialog.setTitle("Dialog Title");
String[] filetypelist = {"A","B","C"};
myDialog.setItems(filetypelist, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
((SettingsFragment) getActivity()).dloadSample(which);
}
});
myDialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
myDialog.create().show();
}
public void dloadSample(int args) {
//SOMETHING TO DO HERE
}
}
答案 0 :(得分:0)
在您的方法中添加:
getActivity()
.getFragmentManager()
.beginTransaction()
.replace(android.R.id.content, new nameOfYourFragmentToBeCalled())
.commit();`