gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
AlertDialog.Builder builder;
Context mContext = getActivity();
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
View layout = inflater
.inflate(R.layout.alertdiaolog_main, null);
GridView gridView2 = (GridView) layout
.findViewById(R.id.alert_gridview);
gridView2.setAdapter(new AlertImageAdapter(getActivity()));
gridView2.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
}
});
builder = new AlertDialog.Builder(mContext);
builder.setNegativeButton("Close",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.setView(layout);
builder.show();
}
});
我有这个代码。当您单击gridView项目时。 alertdialog也将与gridview一起展示。如果用户单击gridView2项目,如何关闭alertdialog?
答案 0 :(得分:1)
使用AlertDialog
AlertDialog Builder
时
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
使用AlertDialog
create
的实例
Dialog dialog = builder.create();
因此,如果需要,您可以通过致电
解雇dialog.dismiss();