كيفاش نصاوب Contacts App بالأندرويد الجزء الاول
فهاد الدرس من سلسلة الاندرويد غادي نقادو واحد التطبيق كيمكن من تسجيل Contacts فقاعدة البيانات كما كيمكن من تعديل بيانات واحد من ل contacts اختاريتو وأيضا كيمكني من مسح هاد ل contact لي اختاريت التطبيق الهدف منو هو تعرف كيفاش تعامل مع قواعد البيانات فالأندرويد.
نظرة سريعة بالفيديو
- الملف button_background.xml
أول حاجة غادي نديروها غادي نفتحو Android Studio وغادي نزيدو مشروع جديد سميتو Contacts منبعد غادي نزيدو ملف فالمجلد res/drawable وغادي تسميه button_background.xml لي غادي يكون هو لbackground ديال واحد ل bouton لي غادي نزيدو من بعد وغادي تمكنا من إضافة contact جديد الكود ديالو هو :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid
android:color="#ff0000"></solid>
</shape>
- الملف activity_contacts_list.xml
فالمجلد res/layout غادي نبدل الإسم ديال الملف activity_main.xml وغادي نسميه activity_contacts_list.xml هاد الملف غادي يمكنا من عرض لائحة كتضم ل contacts لي عندنا فقاعدة البيانات كما غادي تكون فيه واحد ل bouton لي غادي تمكنا من التنقل للصفحة لي غادي تمكنا من إضافة contact جديد لقاعدة البيانات الكود ديالو هو :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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=".ContactsListActivity">
<ListView
android:id="@+id/studentList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
<Button
android:id="@+id/createStudent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:text="+"
android:textColor="#FFFFFF"
android:textSize="28sp"
android:background="@drawable/button_background"
android:elevation="6dp"
android:layout_width="56dp"
android:layout_height="56dp" />
</RelativeLayout>
- الملف activity_form.xml
الملف activity_form.xml لي عبارة عن Formulaire غادي يمكن المستخدم من إدخال المعلومات الخاصة ب contact جديد وإضافتو لقاعدة البيانات الكود ديالو هو :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context="com.example.darijacoding.contacts.FormActivity">
<EditText
android:id="@+id/nom"
android:hint="Nom"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/adresse"
android:hint="Adresse"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/tel"
android:hint="Téléphone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/website"
android:hint="Site web"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/email"
android:hint="Email"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RatingBar
android:id="@+id/rating"
android:max="5"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
- الملف menu_student_form.xml
الملف menu_student_form.xml لي غادي يمكنا من إضافة خاصية حفظ contact فقاعدة البيانات فالقائمة الخاصة بالتطبيق الكود ديالو هو :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="Ok"
android:id="@+id/student_save_item"
android:icon="@drawable/add_user_32px"
app:showAsAction="always"
>
</item>
</menu>