On Long click of any row/itemView display/visible checkbox in all row/itemView

 


(image list maximum 20 ,image like nature,flower)


1)Display image list in recyclerview with name,image

2)On click of image in recyclerview display image in dialog box

3)On Long click of any row/itemView display/visible checkbox in all row/itemView,

4)Display selected/checked image list into next page on submit button



<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyck"/>

</androidx.constraintlayout.widget.ConstraintLayout>




item xml :-



<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
app:cardElevation="5dp"
app:cardCornerRadius="10dp"
android:layout_margin="5dp"
app:cardBackgroundColor="@color/white"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/img"/>

<TextView
android:layout_margin="30dp"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/img"
android:layout_marginEnd="261dp"
android:text="Flower"
android:textSize="40sp" />

<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/img"
android:text="This is flower"
android:textSize="30sp" />

</RelativeLayout>



</androidx.cardview.widget.CardView>





Model Class :-


package com.example.myrecycle;

public class Model {
String name,title;
Integer url;

public Model() {
}

public Model(String name, String title, Integer url) {
this.name = name;
this.title = title;
this.url = url;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public Integer getUrl() {
return url;
}

public void setUrl(Integer url) {
this.url = url;
}
}




Adapter Class :-




package com.example.myrecycle;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class Adapterclass extends RecyclerView.Adapter<Adapterclass.ViewHolder> {

Context context;
List<Model> modelList;
boolean selectmode = false;

public Adapterclass(Context context, List<Model> modelList) {
this.context = context;
this.modelList = modelList;

}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view;
LayoutInflater inflater = LayoutInflater.from(context);
view=inflater.inflate(R.layout.showitem,parent,false);
Model model = new Model();
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) {
Model model = modelList.get(position);
holder.name.setText(modelList.get(position).getName());
holder.title.setText(modelList.get(position).getTitle());
holder.imageView.setImageResource(modelList.get(position).getUrl());

holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder= new AlertDialog.Builder(view.getRootView().getContext());
View dialogView = LayoutInflater.from(view.getRootView().getContext()).inflate(R.layout.flowerdialogbox,null);
ImageView dialogimg;
TextView dialogtext;
dialogimg=dialogView.findViewById(R.id.dialogimg);
dialogtext=dialogView.findViewById(R.id.dialogtextview);
dialogtext.setText(model.getTitle());
dialogimg.setImageResource(model.getUrl());
builder.setView(dialogView);
builder.setCancelable(true);
builder.show();


}
});

holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(),Submitbutton.class);
context.startActivity(intent);
}
});

}

@Override
public int getItemCount() {
return modelList.size();
}

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView name,title;
ImageView imageView;
public ViewHolder(@NonNull View itemView) {
super(itemView);
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);

name=itemView.findViewById(R.id.text1);
title=itemView.findViewById(R.id.text2);
imageView =itemView.findViewById(R.id.img);

}

@Override
public void onClick(View view) {

}

@Override
public boolean onLongClick(View view) {
itemView.setVisibility(view.INVISIBLE);
// Toast.makeText(context.getApplicationContext(), "long Click" + itemView+" ", Toast.LENGTH_SHORT).show();
return false;
}
}
}






package com.example.myrecycle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
List<Model> modelList = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=findViewById(R.id.recyck);
Adapterclass adapterclass = new Adapterclass(this,modelList);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapterclass);
insertdata();


}

private void insertdata() {
// Model model = new Model("Rose","This is rose Flower",R.drawable.rose);
// modelList.add(model);
// model= new Model("Lotus","This is Lotus flower",R.drawable.lotus);
// modelList.add(model);
modelList.add(new Model("Rose","This is rose",R.drawable.rose));
modelList.add(new Model("Buterfly","This is buterfly",R.drawable.buterfly));
modelList.add(new Model("Lotus","This is lotus",R.drawable.lotus));
modelList.add(new Model("Crossandra","This is crossandra",R.drawable.crossanda));
modelList.add(new Model("Golden Shower","This is Golden Shower",R.drawable.goldenshower));
modelList.add(new Model("Forest Ghost","This is Forest Ghost",R.drawable.forestgost));
modelList.add(new Model("Yellow Marigold","This is rose",R.drawable.yello));
modelList.add(new Model("Pot Marigold","This is Pot Marigold",R.drawable.postmerrigold));
modelList.add(new Model("Jasmine","This is Jasmine",R.drawable.jasmin));
modelList.add(new Model("Star Jasmine","This is Star Jasmine",R.drawable.star));
modelList.add(new Model("Night Blooming","This is Night Blooming",R.drawable.night));
modelList.add(new Model("Jasminum Sambac","This is Jasminum Sambac",R.drawable.jasmin));
modelList.add(new Model("Crape Jasmine","This is Crape Jasmine",R.drawable.crossanda));
modelList.add(new Model("Sunflower","This is Sunflower",R.drawable.sunflower));
modelList.add(new Model("Common White","This is Common White",R.drawable.common));
modelList.add(new Model("Hibiscus","This is Hibiscus",R.drawable.hibis));
modelList.add(new Model("Peacock Flower","This is Peacock Flower",R.drawable.peacock));
modelList.add(new Model("Daisy","This is Daisy",R.drawable.daisy));
modelList.add(new Model("Scarlet Milkweed","This is Scarlet Milkweed",R.drawable.scart));
modelList.add(new Model("Black Turmeric","This is Black Turmeric",R.drawable.tulip));

}

}





Self Create New as on click go to next page.....








Comments

Popular posts from this blog

Gride View in Firebase

Register in kotlin

Check Permission in Android Studio