Untitled

mail@pastecode.io avatar
unknown
java
a year ago
2.3 kB
1
Indexable
Never
package com.drunkencoder.twobuttonsapp;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class MainActivity extends AppCompatActivity {

    TextView textView;
    Button button;
    Button buttony;
    int counter = 2;

    ArrayList<Plante> plantes;
    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.textView);
        button = findViewById(R.id.button);
        buttony = findViewById(R.id.button2);
        plantes = new ArrayList<Plante>();


        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(getAssets().open("plantedata.txt")));
            if(reader == null)
                textView.setText("ASD");
            while(reader.readLine() != null) {
                String n = reader.readLine();
                plantes.add(new Plante(n));
            }
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }

        textView.setText(plantes.get(1).getImageSource());

        button.setOnClickListener(new View.OnClickListener() {

            @SuppressLint("SetTextI18n")
            @Override
            public void onClick(View view) {

                textView.setText(""+ plantes.get(counter++).getImageSource());
                //textView.setText("" +(++counter));
            }
        });

        buttony.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textView.setText(""+ plantes.get(counter--).getImageSource());
                //textView.setText("" + (--counter));
            }
        });

    }



    public int decreaseCounter() {
        return --counter;
    }

    public int increaseCounter() {
        return ++counter;
    }
}