Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Dialog after click RecyclerView item?

Tags:

android

I want to open dialog box when i click on RecyclerView item. Toast is working after click show on the screen but not open dialog box.

Code:

  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) {


                }
            });


        }


    }
}
like image 905
Navjot.jassal Avatar asked Apr 28 '17 07:04

Navjot.jassal


1 Answers

add dialog.show();

final Dialog dialog = new Dialog(ctx);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.image_perview);
dialog.show();

FYI

Dialog full screen

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();
like image 89
IntelliJ Amiya Avatar answered Sep 19 '22 12:09

IntelliJ Amiya