Advertisement
AleksandarH

MainActivity

Dec 12th, 2023
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package com.example.a20621646_k2;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.fragment.app.DialogFragment;
  5.  
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.widget.ListView;
  9.  
  10. import java.util.ArrayList;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13.     private static final String TAG = "20621646";
  14.     @Override
  15.  
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_main);
  19.         ArrayList<Clothes> clothesList = new ArrayList<>();
  20.         clothesList.add(new Clothes("T-shirt", 15.99, 50, "USA"));
  21.         clothesList.add(new Clothes("Jeans", 29.99, 30, "Italy"));
  22.         clothesList.add(new Clothes("Dress Shirt", 39.99, 40, "France"));
  23.         clothesList.add(new Clothes("Skirt", 24.99, 25, "Spain"));
  24.         clothesList.add(new Clothes("Sweater", 45.99, 20, "Germany"));
  25.         clothesList.add(new Clothes("Jacket", 59.99, 15, "UK"));
  26.  
  27.         ClothesAdapter adapter = new ClothesAdapter(this, clothesList);
  28.         ListView listView = findViewById(R.id.clothesListView);
  29.         listView.setAdapter(adapter);
  30.  
  31.         listView.setOnItemClickListener((parent, view, position, id) -> {
  32.             Clothes selectedClothes = clothesList.get(position);
  33.             showClothesInfoDialog(selectedClothes);
  34.         });
  35.     }
  36.  
  37.     private void showClothesInfoDialog(Clothes clothes) {
  38.         Log.d(TAG, "Showing Clothes Info Dialog");
  39.         DialogFragment dialogFragment = new ClothesDialogFragment(clothes);
  40.         dialogFragment.show(getSupportFragmentManager(), "ClothesInfoDialogFragment");
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement