HistoriqueActivity.java 1.57 KB
package com.example.martin.projetv5;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import java.util.ArrayList;

/**
 * Created by martin on 18/02/2017.
 */

public class HistoriqueActivity extends AppCompatActivity implements EventAdapter.EventAdapterListener  {

    ArrayList<Event> listEvents = new ArrayList<>();
    EventAdapter adapter = null;
    ListView list = null;

    Event[] tabEvents = null;

    StringBDD eventBDD = null;

    void addEventList(Event ev, ArrayList<Event> listP){
        listP.add(ev);
        adapter.notifyDataSetChanged();
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.historique_layout);

        adapter = new EventAdapter(this,listEvents);
        adapter.addListener(this);
        list = (ListView)findViewById(R.id.list2);
        list.setAdapter(adapter);

        eventBDD = new StringBDD(this);
        eventBDD.open();
        int indMax = eventBDD.getIndiceMaxEvent();
        tabEvents = new Event[indMax];

        for(int j=0; j<indMax; j++){
            Event ev = eventBDD.getEventWithId(indMax-j);
            addEventList(ev,listEvents);
        }
    }

    @Override
    protected void onResume() {
        eventBDD.open();
        super.onResume();
    }

    @Override
    protected void onPause() {
        eventBDD.close();
        super.onPause();
    }

    @Override
    public void onClickButton(Event item, int position) {}


}