我想点击RecyclerView
项目时打开对话框。在屏幕上单击显示但未打开对话框后,Toast正在工作。
代码:
public class Gridview_adapter extends RecyclerView.Adapter<Gridview_adapter.Myholder> {
private ArrayList<Photos_model> list;
private Activity ctx;
public Gridview_adapter(Activity ctx, ArrayList<Photos_model> list) {
this.list = list;
this.ctx = ctx;
}
@Override
public Gridview_adapter.Myholder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_gridview, parent, false);
return new Gridview_adapter.Myholder(view);
}
@Override
public void onBindViewHolder(Gridview_adapter.Myholder holder, int position) {
final Photos_model id = list.get(position);
Picasso.with(ctx).load(list.get(position).getImage()).resize(250, 400).into(holder.image);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(ctx, "Selecteddddddddddddd upper", Toast.LENGTH_SHORT).show();
final Dialog dialog = new Dialog(ctx);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.image_perview);
}
});
}
@Override
public int getItemCount() {
return list.size();
}
public class Myholder extends RecyclerView.ViewHolder {
private ImageView image;
public Myholder(View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.gridimages);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
}
答案 0 :(得分:9)
添加 dialog.show();
final Dialog dialog = new Dialog(ctx);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.image_perview);
dialog.show();
<强> FYI 强>
全屏对话
DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
int DeviceTotalWidth = metrics.widthPixels;
int DeviceTotalHeight = metrics.heightPixels;
final Dialog dialog = new Dialog(ctx);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.image_perview);
dialog.getWindow().setLayout(DeviceTotalWidth ,DeviceTotalHeight);
dialog.show();