First you need to create a xml for list item named list_item.xml and add the following code.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/txt_first" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Demo" android:paddingBottom="10dp" android:textColor="@color/purple_500" android:textSize="20sp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="20dp" android:orientation="horizontal" android:weightSum="2"> <TextView android:id="@+id/txt_second" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Demo" android:textColor="@color/purple_200" android:textSize="14sp"/> <TextView android:id="@+id/txt_third" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Demo" android:gravity="end" android:textColor="@color/purple_200" android:textSize="14sp"/> </LinearLayout> </LinearLayout>
Now create a folder in res folder named anim. On that folder create a file named right_to_left.xml and add following code to it.
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="700"> <translate android:fromXDelta="100%p" android:interpolator="@android:anim/decelerate_interpolator" android:toXDelta="0" /> <alpha android:fromAlpha="0.5" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:toAlpha="1" /> </set>
First you need to create a xml for list item named list_item.xml and add the following code.
<?xml version="1.0" encoding="utf-8"?> <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:animation="@anim/right_to_left" android:animationOrder="normal" android:delay="15%" />
First you need to create a xml for list item named list_item.xml and add the following code.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:orientation="vertical" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView_recent" android:layout_width="match_parent" android:layout_height="match_parent" android:layoutAnimation="@anim/layout_animation_right_to_left" android:overScrollMode="never" /> </LinearLayout> </LinearLayout>
First you need to create a xml for list item named list_item.xml and add the following code.
public class DataModel { String pname; String pprice; String pdiscount; public DataModel(String pname, String pprice, String pdiscount) { this.pname = pname; this.pprice = pprice; this.pdiscount = pdiscount; } public String getPname() { return pname; } public String getPprice() { return pprice; } public String getPdiscount() { return pdiscount; } }
Another Written Description
First you need to create a xml for list item named list_item.xml and add the following code.
public class CustomData { static String[] nameArray = {"Baker Nest", "cakolicious", "Cassey", "Better Blend", "Elavate", "Flame First","Derben daily","Dream Boxes","Fuzico","Hairplane"}; static String[] priceArray = {"10","10","10","10","10","10","10","10","10","10"}; static String[] discountArray = {"15","15","15","15","15","15","15","15","15","15"}; }
First you need to create a xml for list item named list_item.xml and add the following code.
import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder> { private ArrayList<DataModel> dataSet; public static class MyViewHolder extends RecyclerView.ViewHolder { TextView txt_first; TextView txt_second; TextView txt_third; public MyViewHolder(View itemView) { super(itemView); this.txt_first = (TextView) itemView.findViewById(R.id.txt_first); this.txt_second = (TextView) itemView.findViewById(R.id.txt_second); this.txt_third = (TextView) itemView.findViewById(R.id.txt_third); } } public CustomAdapter(ArrayList<DataModel> data) { this.dataSet = data; } @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.list_item, parent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Override public void onBindViewHolder(final MyViewHolder holder, final int listPosition) { TextView txt_first = holder.txt_first; TextView txt_second = holder.txt_second; TextView txt_third = holder.txt_third; txt_first.setText(dataSet.get(listPosition).getPname()); txt_second.setText("$ "+dataSet.get(listPosition).getPprice()); txt_third.setText(dataSet.get(listPosition).getPdiscount()+" % Off"); } @Override public int getItemCount() { return dataSet.size(); } }
First you need to create a xml for list item named list_item.xml and add the following code.
import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import android.os.Bundle; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { RecyclerView.LayoutManager layoutManager; RecyclerView recyclerView; private static ArrayList<DataModel> data; private static RecyclerView.Adapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView=findViewById(R.id.recyclerView_recent); recyclerView.setHasFixedSize(true); layoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); data = new ArrayList<DataModel>(); for (int i = 0; i < CustomData.nameArray.length; i++) { data.add(new DataModel( CustomData.nameArray[i], CustomData.priceArray[i], CustomData.discountArray[i] )); } adapter = new CustomAdapter(data); recyclerView.setAdapter(adapter); } }
First you need to create a xml for list item named list_item.xml and add the following code.