Advertisement
mmayoub

MainActivity.java

Mar 3rd, 2023
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | Software | 0 0
  1. package com.example.mylist;
  2.  
  3. import android.os.Bundle;
  4. import android.widget.Button;
  5.  
  6. import androidx.appcompat.app.AppCompatActivity;
  7. import androidx.recyclerview.widget.LinearLayoutManager;
  8. import androidx.recyclerview.widget.RecyclerView;
  9.  
  10. import java.util.ArrayList;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13.     private RecyclerView rcvItems;
  14.     private Button btnOK;
  15.  
  16.     private ArrayList<Item> data;
  17.     private MyAdapter adapter;
  18.  
  19.     @Override
  20.     protected void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.activity_main);
  23.  
  24.         rcvItems = findViewById(R.id.rcvItems);
  25.         btnOK = findViewById(R.id.btnOK);
  26.  
  27.         data = new ArrayList<>();
  28.        
  29.         data.add(new Item("Saleh", 10));
  30.         data.add(new Item("Ali", 15));
  31.         data.add(new Item("Amneh", 20));
  32.         data.add(new Item("Saleh", 10));
  33.         data.add(new Item("Ali", 15));
  34.         data.add(new Item("Amneh", 20));
  35.         data.add(new Item("Saleh", 10));
  36.         data.add(new Item("Ali", 15));
  37.         data.add(new Item("Amneh", 20));
  38.         data.add(new Item("Saleh", 10));
  39.         data.add(new Item("Ali", 15));
  40.         data.add(new Item("Amneh", 20));
  41.         data.add(new Item("Saleh", 10));
  42.         data.add(new Item("Ali", 15));
  43.         data.add(new Item("Amneh", 20));
  44.         data.add(new Item("Saleh", 10));
  45.         data.add(new Item("Ali", 15));
  46.         data.add(new Item("Amneh", 20));
  47.         data.add(new Item("Saleh", 10));
  48.         data.add(new Item("Ali", 15));
  49.         data.add(new Item("Amneh", 20));
  50.         data.add(new Item("Saleh", 10));
  51.         data.add(new Item("Ali", 15));
  52.         data.add(new Item("Amneh", 20));
  53.  
  54.  
  55.         adapter = new MyAdapter(data);
  56.         RecyclerView.LayoutManager manager = new LinearLayoutManager(this);
  57.  
  58.         rcvItems.setLayoutManager(manager);
  59.         rcvItems.setAdapter(adapter);
  60.  
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement