- package com.example.student.myapplication;
- 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 {
- Button button1, button2;
- ImageView imageView;
- int num = 0;
- int p = 0, count;
- int[] imageID = new int[6];
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- init();
- }
- public void init() {
- button1 = (Button) findViewById(R.id.button1);
- button2 = (Button) findViewById(R.id.button2);
- imageView = (ImageView) findViewById(R.id.imageView);
- imageID[0] = R.drawable.img01;
- imageID[1] = R.drawable.img02;
- imageID[2] = R.drawable.img03;
- imageID[3] = R.drawable.img04;
- imageID[4] = R.drawable.img05;
- imageID[5] = R.drawable.img06;
- }
- public void Button1(View view)
- {
- if(num==1)
- {
- num+=0;
- setTitle("第 " + (p + 1) + " / " + count + " 張");
- }
- else
- num--;
- setTitle("第 " + (p - 1) + " / " + count + " 張");
- imageView.setImageResource(imageID[num-1]);
- }
- }
複製代碼 |