Android - Showing value taken from SQLite db to a TextView

78 Views Asked by At

I want to get the String taken from SQLite db and write it into a textview.

Here's the code for my MainClass which tries to call the value from SQLite db :

public class MainActivity extends Activity {
    private ChosenSlotDAO chosenSlotDAO = new ChosenSlotDAO(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        //String hoho = "Hohoho";

        chosenSlotDAO.open();
        TextView chosenSlotView = (TextView) findViewById(R.id.chosenSlotTView);

        String slots = chosenSlotDAO.getSlot();
        chosenSlotDAO.createSlot(slots);

        if(slots == null)
        {
            chosenSlotView.setText("You have not parked");
        }
        else
        {
            chosenSlotView.setText(slots);
        }

        chosenSlotDAO.close();
    }
}

What I am trying to do here is to automatically show user's parking location.

I have this snippet in my MainMap class which comes after tapping NFC at the entrance of the parking slot :

chosenSlotDAO.open();
chosenSlotDAO.dropTable();
chosenSlotDAO.close();

So basically whenever user taps the entrance NFC the table is dropped to show that user isn't parked(this is a software prototype, it is supposed to be exit NFC, but as exit is not in the scope of my application development, as a convenience, I placed the code in entrance).

This is my dropTable() code :

public void dropTable() {
    database.execSQL("DROP TABLE IF EXISTS " + ChosenSlotDatabaseHandler.TABLE_CHOSEN_PARKING_SLOT);
}

Does the drop table mess with the value inside the textview?

If no, then what could be wrong?

0

There are 0 best solutions below