In screen 1, there are 10buttons, such as tv, fan, lamp, iron, laptop. When I clicked the tv button, it will pass 'tv' into the appliance column in SQLite and goes into another activity where user input power and usage. The power n usage will go into SQLite under same row as tv.
The same goes for fan, lamp, etc. User will not need to key in appliance name, only power and usage. How can i make sure the name of appliance connected to power and usage? Thanks
SQLite input data through multiple buttons and activity
Post a Reply
|Oldest Newest Rating|
· January 14, 2016
I'm assuming that after clicking the button you're directly led to the next activity (btw: I'd use a fragment for that, not a different activity).
Two things you could do:
1. Pass the the information about which button has been clicked along to the next activity by using:
Then get the additional infos. After you have them you write all the information into the database. That way you don't need to identify which row your appliance is assigned to and you don't have to open your database twice.
2. If you want to keep it the way it is you can push the following sql to your database which will just work as well:
The important part is the WHERE clause. This will search for the row where appliance is what you've specified.
I'd suggest to use the first method because it is way more dynamic. I'm also new to android programming but from my general understanding of coding the first one makes more sense. In order to write to the correct column in your table you need to pass which button was clicked to the next activity anyways.
I hope I could help you!
Java / Android Development
Very popular language used to create desktop applications, website applets, and Android apps.
|Bucky Roberts Administrator|