@Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    manager = new SQLiteManager(this);
    try {
      manager.open();
      adapter = new DBTestAdapter(this, manager.selectBuys());
    } catch (SQLException e) {
      e.printStackTrace();
    }
    finish();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    fab = (FloatingActionButton) findViewById(R.id.fab);

    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            showDialog();
          }
        });

    listView = (ListView) findViewById(R.id.lv_db_test);

    listView.setAdapter(adapter);

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            adapter.remove(position);

            Snackbar.make(
                    fab,
                    "" + manager.deleteBuy(adapter.getItem(position).getId()),
                    Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });
  }
 @Override
 protected void onDestroy() {
   manager.close();
   super.onDestroy();
 }