image application for android

Activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout
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"
   
tools:context="com.example.readerpdf.imageapp.MainActivity">

    <Button
       
android:id="@+id/button2"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:layout_alignParentBottom="true"
       
android:layout_centerHorizontal="true"
       
android:layout_marginBottom="16dp"
       
android:text="@string/button_text_txt" />

    <ImageView
       
android:id="@+id/imageView"
       
android:layout_width="320sp"
       
android:layout_height="430sp"
       
android:layout_alignParentTop="true"
       
android:layout_centerHorizontal="true"
       
android:layout_marginTop="15dp"
        
app:srcCompat="@mipmap/png_image" />

</android.widget.RelativeLayout>
 

MainActivity.java


package com.example.readerpdf.imageapp;



import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.ImageView;



public class MainActivity extends AppCompatActivity {



    private Button button;

    private ImageView imageView;



    private int current_image_index;

    int[] images  = {R.mipmap.ic_launcher_foreground,R.mipmap.ic_launcher};



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        onClickListener();

    }



    public void onClickListener(){

        imageView = findViewById(R.id.imageView);

        button = findViewById(R.id.button2);



        button.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                current_image_index++;

                current_image_index = current_image_index % images.length;

                imageView.setImageResource( images[current_image_index]);

            }

        });

    }

}
 


output

 
Share on Google Plus

About super super

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.