Hai, kawan-kawan kali ini saya akan membuat tutorial CRUD (Create Read Update Delete) Android dengan menggunakan database Mysql untuk perantaranya menggunakan file php. Program yang saya buat adalah data produk dimana nantinya kita bisa membuat( create ), mengedit( Update ), membaca( read ), dan menghapus( delete ) data.
I have my school project where I need to fetch values from MySQL database and display it to Spinner in Android.I am using Android Studio and Volley Library for the networking operation but confused how to achieve this thing. I'll appreciate your help. Thank You :)
Emma WilsonEmma Wilson
3 Answers
You have to first create a php script that will print the data of your mysql database in json format.. Here I am showing you an example lets see this is my database
Now suppose I need to load all the username of this table to android's spinner. So this is the php script that will give me the data in json format
The above php code will give the following json
Now android code will be MainActivity.java
Source Android Spinner Example with MySQL Database
Belal KhanBelal Khan
- Query your Database
- Fetch the results
- Encode the data into JSON format
- Request and parse results in your app
- Populate a list array for the spinner
- Set the adapter on your spinner
medameda
Virendra PariharVirendra Parihar
Not the answer you're looking for? Browse other questions tagged android or ask your own question.
currently I am developing an app for my final class in college. The concept of the app is a Contact keeping app, essentially a user will be greeted by a login screen where they can either login if they already have an account or register if they don't. When you register the user will be prompt to enter their name, username, password and email. They then submit it and they will again be greeted by the login screen where they can now login in with their recently created credentials. Once they login successfully they be be show an Activity that welcomes them with their name that is retrieved from the table in the database by matching the username and password on the login, it retrieves all the information in that row. I pretty much have that down but what I am having trouble with is where am I going to hold the contacts that the users wants to save, I know that is has to be in another table but how am I going to set it up so I can match the a certain user to all of their contacts in the other table.
Once I get that information I need to put it on a ListView so the user can see their contacts and scroll through them, they can then add, delete or edit them.
As of right now I am able to register, login and display the welcome screen with no problem now I just need to be able to add, delete and edit contacts.
Java is used for the Android Studio part and PHP is used for the file that make the connection in the host online.
I am using Volley and JSON request.
The database and PHP files that make the request to the database are hosted in 000webhost.
T. EsparzaT. Esparza
2 Answers
This seems like a simple CRUD application.If you use a RESTful communication model it's quite simple to achieve.As for storing the contacts, you can have a file specific to each user and have that file's URI on the user's table in the DB. The file can be CSV, or JSON which is easily convertable into POJOs with the right API.
Good luck.
ricol070ricol070
First, create a MySQLite Helper class
Then a model class
Then a datasource
You access the datasource as follows:
You can display the info in a listview by calling ContactsDataSource.getAllContacts(), and displaying the results using a custom listAdapter. The idea is that you will use the Data Source's functions to grab the data you want, and feed it into the model class. From there you can extract what you need for the listview. Let me know if you need more help with that.
You also mentioned wanting to make multiple tables in the database, and that is as easy as using the above code but just adding another variable, such as TABLE_CONTACTS2 = 'contacts2', and duplicating the functions for that table.
emhomm4emhomm4