ورود

View Full Version : مشکل در استفاده از fragment



4EBRAHIM4
جمعه 30 بهمن 1394, 11:02 صبح
سلام به همه اندروید دوستان
من به تازگی شروع یه یادگیری اندوید کردم و الانم دارم با fragment ها دست و پنچه نرم می کنم
یه برنامه کوچیک نوشتم تا با fragment آشنا بشم ولی ارور داد بعد از کمی حلاجی فهمیدم که زمانی که توی activity_main.xml از<fragment> استفاده میکنم برنامه ارور میده وحتی اجرا هم نمیشه
اگه کسی میدونه که مشکل از کجاس لطفا بگه
ارادتمند

<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.ebrahim.testfragment.MainActivity"
tools:showIn="@layout/activity_main"
android:orientation="vertical"
android:weightSum="1">


<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="B1"
android:id="@+id/button1" />

<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment" />

</LinearLayout>

rezaricky
جمعه 30 بهمن 1394, 18:17 عصر
سلام . کد اصلا معلوم نیست
اینو ببین https://stackoverflow.com/questions/19874882/android-view-inflateexception-binary-xml-file-error-inflating-class-fragment/35436245#35436245

4EBRAHIM4
یک شنبه 02 اسفند 1394, 06:11 صبح
فرقی به حالم نکرد

rezaricky
یک شنبه 02 اسفند 1394, 08:16 صبح
عزیز کدی که گذاشتی رو ببین
فرگمنت رو درست تعریف نکردی
android:name و layout باید باشه.

<fragment
android:id="@+id/fragment_food_image_gallery"
android:name="ir.smartrestaurant.ui.fragment.ImageGalleryFragmen t"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout="@layout/fragment_image_gallery"
tools:layout="@layout/fragment_image_gallery" />