package com.example.checkregister;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

public class CheckRegisterListActivity extends ListActivity {
  private CheckRegisterCursorAdapter mca;
  private Cursor cursor;
  private CheckRegisterDBAdapter dba;
  private Context context;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = (Context) this;
    dba = new CheckRegisterDBAdapter(this);
    cursor = dba.getCheckList();
    mca = new CheckRegisterCursorAdapter(context, cursor);
    setListAdapter(mca);
  }

  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    String msg = "Position: " + position + " ID: " + id;
    Toast toast = Toast.makeText(context, msg, Toast.LENGTH_LONG);
    toast.show();
    Intent checkEdit = new Intent(this, CheckRegisterActivity.class);
    checkEdit.putExtra("ID", id);
    startActivity(checkEdit);
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    dba.close();
  }

}
