/
ap1k
/
MultimediaJavaAndroid
Обзор
Документация
Войти
/
ap1k
/
MultimediaJavaAndroid
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/src/main/java/com/example/multimedia/PhotoGalleryActivity.java
93 строки
3 KB
Roman
Full proj
11 май 2025, 13:58
11 май 2025, 13:58
4ffd117
Код
Авторство
О чём код?
package com.example.multimedia; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class PhotoGalleryActivity extends AppCompatActivity { private ImageView ivPhotoDisplay; private TextView tvPhotoCounter; private Button btnPreviousPhoto, btnNextPhoto; // Sample photos array (can be replaced with actual photos) private final int[] photoResources = { R.drawable.photo1, R.drawable.photo2, R.drawable.photo3 }; private int currentPhotoIndex = 0; private final int totalPhotos = photoResources.length; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_photo_gallery); // Initialize views ivPhotoDisplay = findViewById(R.id.ivPhotoDisplay); tvPhotoCounter = findViewById(R.id.tvPhotoCounter); btnPreviousPhoto = findViewById(R.id.btnPreviousPhoto); btnNextPhoto = findViewById(R.id.btnNextPhoto); // Set initial photo displayCurrentPhoto(); // Setup button click listeners btnPreviousPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showPreviousPhoto(); } }); btnNextPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showNextPhoto(); } }); } /** * Display the current photo and update counter text */ private void displayCurrentPhoto() { // Set the image resource ivPhotoDisplay.setImageResource(photoResources[currentPhotoIndex]); // Update the counter text String counterText = getString(R.string.photo_count, currentPhotoIndex + 1, totalPhotos); tvPhotoCounter.setText(counterText); } /** * Navigate to the previous photo */ private void showPreviousPhoto() { // Decrease index and handle circular navigation currentPhotoIndex--; if (currentPhotoIndex < 0) { currentPhotoIndex = totalPhotos - 1; } // Display the updated photo displayCurrentPhoto(); } /** * Navigate to the next photo */ private void showNextPhoto() { // Increase index and handle circular navigation currentPhotoIndex = (currentPhotoIndex + 1) % totalPhotos; // Display the updated photo displayCurrentPhoto(); } }