我有一个dialogfragment,它的视图包含一个简单的搜索栏和正负按钮。当我解除对话碎片onclick时,会创建一个新的对话碎片并显示出来。在第二次单击按钮后,对话框被取消,但我的愿望是在第一次点击后解雇。另外我应该注意,我的活动包含两个片段,我从第一个片段调用dialog.show()。
MyListFragment.java
FragmentManager manager = getFragmentManager();
fndSrchFragment dialog = new fndSrchFragment();
dialog.setTargetFragment(MyListFragment.this, REQUEST_COLOR);
dialog.show(manager, SRCH_FND);
fndSrchFragment.java
public class fndSrchFragment extends DialogFragment {
.
.
//variable definition
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.color_picker, null);
rSb=(SeekBar) view.findViewById(R.id.r_seek_bar);
.
.
//code for interacting with seekbar
.
.
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(view);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int ccolor = android.graphics.Color.rgb(rComponent, gComponent, bComponent);
sendResult(Activity.RESULT_OK, ccolor);
// two click is needed for dismiss which I don't know why?
dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// two click is needed for dismiss which I don't know why?
dismiss();
}
});
return builder.create();
}
先谢谢你。
答案 0 :(得分:1)
在onMenuItemActionExpand()
内设置日志命令。我打赌你在解除对话后立刻就会看到这个方法。最有可能的是,一旦焦点从对话框返回到活动,系统就会调用此方法。您应该在dialog.show()
之内调用onOptionsItemSelected(MenuItem item)
,而不是$student_mark = array();
foreach($studen_id as $row){
$mark_obtained = ......
$student_mark[] = $mark_obtained;
....
。