(إعداد واجهة تطبيق الأندرويد) ربط تطبيق أندرويد مع MySQL و PHP و JSON

السلام عليكم ورحمة الله وبركاته

(جاري تحديث الموضوع)

فهرس سلسلة دروس ربط تطبيق أندرويد مع MySQL و PHP و JSON :

  1. مقدمة وشرح توضيحي عن Web Services وعن المشروع.
  2. إعداد السيرفر المحلي WAMP و بناء قاعدة بيانات MySQL.
  3. التعامل مع PHP لبناء Web Service  تقوم بعمل Login و Register (مع شرح مبسط عن JSON) .
  4. التعامل مع PHP لبناء Web Service  بجلب بيانات المستخدمين الموجودة بقاعدة البيانات.
  5. بناء مشروع أندرويد  جديد و إعداد واجهة تطبيق الأندرويد.
  6. تطوير كلاسات Register و Login وJSONParser في أندرويد.
  7. تطوير UsersActivity و ListViewAdapter لعمل قائمة المستخدمين بالتنسيق الذي نحتاجه.

 

 

AndroidManifest.xml

لا تنسى تغيير اسم الباكج
package=”com.ahmaadssb.androidwebservices”

<?xml version="1.0" encoding="utf-8"?>
<!-- 

 @author Ahmadssb
 Created by ahmadssb on 2014-12-13
 Website: http://www.ahmadssb.com
 Email: [email protected]
 Facebook: https://www.facebook.com/ahmadssbblog
 Twitter: https://twitter.com/ahmadssb
 YouTube: http://www.youtube.com/user/ahmadssbblog

 لا تنسى تغيير اسم الباكج   
package="com.ahmaadssb.androidwebservices"
 -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    
    package="com.ahmaadssb.androidwebservices"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <activity android:label="Register Activity" android:name=".RegisterActivity"></activity>
        
        <activity android:label="Users Activity" android:name=".UsersActivity"></activity>
    </application>

</manifest>

 

activity_main.xml

<!-- 

 @author Ahmed Saleh
 Created by ahmadssb on 2014-12-13
 Website: http://www.ahmadssb.com
 Email: [email protected]
 Facebook: https://www.facebook.com/ahmadssbblog
 Twitter: https://twitter.com/ahmadssb
 YouTube: http://www.youtube.com/user/ahmadssbblog

 -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ahmaadssb.androidwebservices.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="إسم المستخدم"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/edtUsername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="كلمة المرور"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/edtPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:ems="10"
        android:inputType="textPassword" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center" >

        <Button
            android:id="@+id/btnLogin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="تسجيل الدخول" />

        <Button
            android:id="@+id/btnRegisterUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="مستخدم جديد" />

    </LinearLayout>

</LinearLayout>

 

register_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 

 @author Ahmed Saleh
 Created by ahmadssb on 2014-12-13
 Website: http://www.ahmadssb.com
 Email: [email protected]
 Facebook: https://www.facebook.com/ahmadssbblog
 Twitter: https://twitter.com/ahmadssb
 YouTube: http://www.youtube.com/user/ahmadssbblog

 -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="اسم المستخدم"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/edtRegisterUserName"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="الإسم الكامل"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/edtRegisterDisplayName"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

    <TextView
        android:id="@+id/textView3"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="كلمة المرور"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/edtRegisterPassword"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/btnRegister"
        android:layout_gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="تسجيل" />

</LinearLayout>

 

users_layout.xml

 

<?xml version="1.0" encoding="utf-8"?>
<!-- 

 @author Ahmed Saleh
 Created by ahmadssb on 2014-12-13
 Website: http://www.ahmadssb.com
 Email: [email protected]
 Facebook: https://www.facebook.com/ahmadssbblog
 Twitter: https://twitter.com/ahmadssb
 YouTube: http://www.youtube.com/user/ahmadssbblog

 -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

 

single_user_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 

 @author Ahmed Saleh
 Created by ahmadssb on 2014-12-13
 Website: http://www.ahmadssb.com
 Email: [email protected]
 Facebook: https://www.facebook.com/ahmadssbblog
 Twitter: https://twitter.com/ahmadssb
 YouTube: http://www.youtube.com/user/ahmadssbblog

 -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:src="@drawable/ic_launcher" />

        <android.support.v7.widget.Space
            android:id="@+id/space1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.1"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/txtID"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Large "
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <android.support.v7.widget.Space
                    android:id="@+id/space2"
                    android:layout_width="5dp"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/txtUsername"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.6"
                    android:text="Large"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

            </LinearLayout>

            <TextView
                android:id="@+id/txtDisplayName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_gravity="center"
                android:text="Large "
                android:textAppearance="?android:attr/textAppearanceLarge" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

بإمكانك تحميل المشروع من خلال GitHub :
https://github.com/ahmadssb/Android-PHP-MySQL-JSON-Tutorial.git

2 Comments

Add a Comment
  1. WordPress › Error

    There has been a critical error on this website.

    Learn more about troubleshooting WordPress.