Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.a20621646_k2;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.fragment.app.DialogFragment;
- import android.os.Bundle;
- import android.util.Log;
- import android.widget.ListView;
- import java.util.ArrayList;
- public class MainActivity extends AppCompatActivity {
- private static final String TAG = "20621646";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ArrayList<Clothes> clothesList = new ArrayList<>();
- clothesList.add(new Clothes("T-shirt", 15.99, 50, "USA"));
- clothesList.add(new Clothes("Jeans", 29.99, 30, "Italy"));
- clothesList.add(new Clothes("Dress Shirt", 39.99, 40, "France"));
- clothesList.add(new Clothes("Skirt", 24.99, 25, "Spain"));
- clothesList.add(new Clothes("Sweater", 45.99, 20, "Germany"));
- clothesList.add(new Clothes("Jacket", 59.99, 15, "UK"));
- ClothesAdapter adapter = new ClothesAdapter(this, clothesList);
- ListView listView = findViewById(R.id.clothesListView);
- listView.setAdapter(adapter);
- listView.setOnItemClickListener((parent, view, position, id) -> {
- Clothes selectedClothes = clothesList.get(position);
- showClothesInfoDialog(selectedClothes);
- });
- }
- private void showClothesInfoDialog(Clothes clothes) {
- Log.d(TAG, "Showing Clothes Info Dialog");
- DialogFragment dialogFragment = new ClothesDialogFragment(clothes);
- dialogFragment.show(getSupportFragmentManager(), "ClothesInfoDialogFragment");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement