Create a new project in your Android Studio by filling the required details.
Here the sample project was created by Eclipse IDE.
Download Android Studio
Facing issue on project import in Android Studio visit this Android Studio issues
Step by Steps
1. Create new project in Eclipse IDE by going to File ⇒ New ⇒ Android Project and name the Activity class name as MainActivity.
2. Open your AndroidManifest.xml file and add following code. First i am adding all the classes i am creating to manifest file. Also i am adding INTERNET Connect permission. This connection is required must.
<!-- Internet Permissions --> <uses-permission android:name="android.permission.INTERNET" />
3. Now create a new xml file under res ⇒ layout folder and name it as main.xml This layout file contains two simple buttons to view all products and add a new product.
4. Open you main activity class which is MainActivity.java and write click events for two button which are mentioned in main.xml layout.
5. Now we need an Activity display all the products in list view format. As we know list view needs two xml files, one for listview and other is for single list row. Create two xml files under res ⇒ layout folder and name it as all_products.xml and list_item.xml
6. Create a new class file and name it as AllActivity.java. In the following code
6.1 First a request is send to get_products.php file using a Background Async task thread.
6.2 After getting JSON from get_all_products.php, i parsed it and displayed in a listview.
6.3 If there are no products found AddNewAcivity is launched.
7. Create a new view and activity to add a new product into mysql database. Create a simple form which contains EditText for product name, price and description.
Create a new xml file and name it as add_product.xml and paste the following code to create a simple form.
8. Now create new Activity to insert a new product into mysql database. Create a class file and name it asNewtActivity.java and type the following code. In the following code
8.1 First new product data is read from the EditText form and formatted into a basic params.
8.2 A request is made to create_product.php to create a new product through HTTP post.
8.3 After getting json response from create_product.php, If success bit is 1 then list view is refreshed with newly added product.
Sample Project:
https://github.com/iDevAndroid/MySQLPHP
No comments:
Post a Comment