I have a layout.xml in which when I click a button, the app looks for data on an online database. Imagine an app that goes on a DB online to see how many items are left for online purchases.
Now, I set the check for internet connectivity, I can set an action through the onClick class and I use the HttpGet but, how do I look for an information in a database online? Is there any ID for this item, or parameters to be used? How did you set your database, so as to be used to let information be found?
Thanks in advance!
That is a large answer but lets try.
First of all you have to build a
.php
file that will export your database data into a json array.An example is below:
Now since you have a jsonArray with all database data you are going to have to set it as a String URL and call it through AsyncTask in your Activity or Fragment.
Another example is this:
Global Variables:
And now comes the tricky part:
AsyncTask:
The adapter Class:
The Class for each Item in the ListView:
Modify as you wish.
And the Layout for each
list_item.xml
Hope i helped give you a small idea.
If you are talking about using your own or creating your own database, you can create a MySQL Database and write tables for your items. Then search, filter, add and delete items in your table using SQL queries.
You can also check out Parse which is a backend service with an Android SDK that allows you to store items and data online in the cloud.