Error when loading fragment from activity - java

I am new to android studio and am having some trouble with starting a fragment from an activity. I used code from on here to display the fragment and it was working up until now. I am using a third party library called 'DecoView' which needs to extend fragment, all the code is in 'LineDetails' (its too long to add all code). Does anyone recognise this error below?
Thank you in advance!
LINE DETAILS XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/fragment_place"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<com.hookedonplay.decoviewlib.DecoView
android:layout_width="250dp"
android:layout_height="200dp"
android:id="#+id/dynamicArcView"
android:layout_marginLeft="40dp"
android:layout_marginRight="8dp"
android:layout_marginTop="5dp">
</com.hookedonplay.decoviewlib.DecoView>
<EditText
android:id="#+id/actual"
android:inputType="number"
android:layout_width="150dp"
android:layout_height="46dp"
android:background="#drawable/border"
android:gravity="center"
android:hint="Enter Actual"
android:text=""
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="15sp"
android:layout_marginStart="26dp"
android:layout_alignBottom="#+id/textPercentage"
android:layout_alignStart="#+id/dynamicArcView" />
<Button
android:id="#+id/actual_btn"
android:layout_width="68dp"
android:layout_height="50dp"
android:background="#drawable/actualbutton"
android:shadowColor="#A8A8A8"
android:text="+"
android:textColor="#FFFFFF"
android:layout_above="#+id/textViewProgress"
android:layout_toEndOf="#+id/actual"
android:layout_marginLeft="12dp"/>
<TextView
android:id="#+id/textViewProgress"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginTop="15dp"
android:layout_below="#+id/actual"
android:layout_alignEnd="#+id/actual_btn"
android:layout_marginEnd="14dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:textSize="40sp"
android:id="#+id/textPercentage"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
/>
<TextView
android:id="#+id/textViewLineType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="86dp"
android:text=""
android:textSize="40dp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="#f15623"
android:layout_alignTop="#+id/dynamicArcView"
android:layout_toEndOf="#+id/dynamicArcView" />
<Button
android:id="#+id/buttonViewDetails"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#mipmap/info"
android:layout_marginLeft="250dp"
android:onClick="verifyButton"
android:layout_alignParentBottom="true"
android:layout_marginBottom="14dp" />
</RelativeLayout>
</RelativeLayout>

<fragment
android:id="#+id/fragment_name"
class="com.almac.tracker.LineDetails"
android:layout_width="match_parent"
android:layout_height="match_parent" />
"xmlns:android="http://schemas.android.com/apk/res/android"
is missing
use below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:id="#+id/fragment_name"
class="com.almac.tracker.LineDetails"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

Try adding
tools:context="com.yourpackagehere.FragmentThatIsInflatingTheXml">
to your first layout, the Relative one. Pls note that you have to change "yourpackagehere" with the name of your package and "FragmentThatIsInflatingTheXml" with the name of the actual Fragment

You said that DecoView extends a fragment so it should be added like this:
<fragment
android:id="#+id/fragment_id"
android:name="com.hookedonplay.decoviewlib.DecoView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Related

How to have auto complete text in android studio without having to create an array

I watched this video of auto complete text. However, for this one he made an array with all but another video at 1:54 he shows off a text box that comes up that seems to be powered by Google. I am wondering how can I get this auto complete to come up for me? I know there is auto complete text you can get in Android Studio, but that is not what I want to use.
Here is my XML code:
<?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:onClick="onClick"
tools:context=".MainActivity">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:layout="#layout/activity_main" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:orientation="horizontal"
android:layout_marginEnd="60dp">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.01"
android:ems="10"
android:hint="Enter starting location" />
<Button
android:id="#+id/B_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Search" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="98dp"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.01"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="#+id/B_hospital"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Hospitals" />
<Button
android:id="#+id/B_restaurant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Restaurants" />
<Button
android:id="#+id/B_school"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Schools" />
<Button
android:id="#+id/B_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/map"
android:onClick="onClick"
android:text="To" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Android layout_weight iframe and scroll

sorry for my poor english in advance
I have a design problem on android studio.
I used multiples devices (From version 8 to 10) and it works fine, and one device (version 6) which has a different output (you can check my screens below)wrong display click here
good display click here
unfortunately i don't know why it goes wrong, it might be a problem with layout_weight, in my code i use a Frame layout to switch out between differents Views, it looks like the Framelayout doesn't take any height (i want it to take the available space)
Thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/choose_model"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<Spinner
android:id="#+id/select_your_model"
android:layout_width="43dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/text_model_title"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/text_model_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:text="#string/choose_mod"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/Spinner_model_preference_text"
android:layout_width="160dp"
android:layout_height="26dp"
android:layout_alignTop="#+id/select_your_model"
android:layout_alignParentEnd="true"
android:layout_marginEnd="45dp"
android:gravity="center"
android:textColor="#android:color/darker_gray"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:background="#FAFAFA">
<FrameLayout
android:id="#+id/Frame_layout_preferences_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="0">
<Button
android:id="#+id/save_user_preferences"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/save" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_preferences_model"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/recycler_view_preferences_model"
android:layout_alignParentStart="true"
android:background="?android:attr/listDivider" />
</RelativeLayout></LinearLayout>
You have the problem, because you have a FrameLayout inside a fragment. I recommend the next
If you only want to have a view and it has different content, you can have a activity
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<Spinner
android:id="#+id/select_your_model"
android:layout_width="43dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/text_model_title"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/text_model_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:text="#string/choose_mod"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/Spinner_model_preference_text"
android:layout_width="160dp"
android:layout_height="26dp"
android:layout_alignTop="#+id/select_your_model"
android:layout_alignParentEnd="true"
android:layout_marginEnd="45dp"
android:gravity="center"
android:textColor="#android:color/darker_gray"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:background="#FAFAFA">
<FrameLayout
android:id="#+id/Frame_layout_preferences_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="0">
<Button
android:id="#+id/save_user_preferences"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/save" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_preferences_model"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<View
android:id="#+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/recycler_view_preferences_model"
android:layout_alignParentStart="true"
android:background="?android:attr/listDivider" />
</RelativeLayout></LinearLayout>
Replace the FrameLayout with an imageview
if you want to have fragments. i recommend the next
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Call the fragment in activity
getSupportFragmentManager().beginTransaction()
.replace(R.id.main_container, fragment, fragment.getClass().getSimpleName()).addToBackStack(null).commit();

How to prevent overlapping of buttons and other objects?

When i preview with android emulator, the layout preview is ok. But when I install the app in my mobile the views overlaps. It may be because of lack of space in the mobile screen but I have no idea. Please help me out. And also help me with making this app to work with all screen sizes. Thanks in advance.
First image is emulator preview 2nd is mobile preview
Here is the xml code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns: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="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:orientation="vertical"
android:background="#drawable/newbackground"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
app:srcCompat="#drawable/dicee_logo" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/dicee_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/dice1" />
<ImageView
android:id="#+id/dicee_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/dice2" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="61dp"
android:background="#color/colorPrimary"
android:text="#string/button_text"
android:textColor="#android:color/white" />
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/roll_button"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/roll_button"
android:layout_marginBottom="25dp"
android:background="#android:color/holo_blue_light"
android:text="Next page" />
</RelativeLayout>
</LinearLayout>
This will keep the 2 textview to bottom and will expand in whatever view you use
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="#drawable/ic_word" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/dicee_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/ic_word" />
<ImageView
android:id="#+id/dicee_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="#drawable/ic_pdf" />
</LinearLayout>
<Button
android:id="#+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#color/colorPrimary"
android:text="text"
android:textColor="#android:color/white" />
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:background="#android:color/holo_blue_light"
android:text="Next page" />
</LinearLayout>
Try the below modified code. Since you want the buttons below each other. You cannot place one on right of other, so remove the alignRight.
<Button
android:id="#+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
**android:layout_marginTop="21dp"**
android:background="#color/colorPrimary"
android:text="#string/button_text"
android:textColor="#android:color/white" />
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/roll_button"
android:layout_alignParentBottom="true"
**android:layout_alignRight="#+id/roll_button"**
android:layout_marginBottom="25dp"
android:background="#android:color/holo_blue_light"
android:text="Next page" />

Error on android UI

I'm Learner and designing an interface but there is little problem can some one help me out, attaching screen shot original and my design and also code.
I'm unable to adjust the button position in layout, and also if some one have links or stuff related beginners then also share
thanks.
Here is my XML code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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:id="#+id/activity_home__screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.sofagold.mrdeveloper.sofagold.Home_Screen"
android:background="#android:color/black">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.8">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/home_header"
android:layout_weight="1.3">
<Button
android:layout_width="62dp"
android:layout_height="wrap_content"
android:id="#+id/button3"
android:background="#drawable/home_home"
android:layout_gravity="start"
android:padding="5dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/home_small_logo"
android:id="#+id/imageView"
android:adjustViewBounds="true"
android:baselineAlignBottom="false"
android:layout_gravity="center"
android:layout_weight="5000" />
<Button
android:layout_width="59dp"
android:layout_height="wrap_content"
android:id="#+id/button8"
android:background="#drawable/home_back"
android:layout_gravity="start"
android:padding="5dp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.2">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/button24"
android:layout_toEndOf="#+id/button25"
android:layout_marginStart="64dp"
android:layout_marginTop="8dp"
android:id="#+id/button22"
android:layout_wieght="5"
android:background="#drawable/home_btn_bg" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/button22"
android:layout_marginBottom="48dp"
android:id="#+id/button24"
android:button_size="5dp"
android:background="#drawable/home_btn_bg" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/button24"
android:id="#+id/button25"
android:button_size="5dp"
android:background="#drawable/home_btn_bg" />
RelativeLayout(end of)
</LinearLayout>
</LinearLayout>

Android - Issue with size of EditText in Layout xml

I am having a problem with the layout xml for my fragment... I think it may be because the layout was originally made for just an activity, and then later it was changed to a fragment. It looks like this in my editor:
But in my phone and emulator, it ends up like this:
Can anyone think of a solution for me? I've tried out multiple things but cannot seem to fix it, as i think maybe the rules are a little different when working with fragments? Thank you for all and any help!!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<EditText android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/body" />
<EditText android:id="#+id/body" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" />
<Button android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Layout file for the activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="130dp"
android:layout_toRightOf="#+id/textView1" >
</FrameLayout>
</LinearLayout>
Just change android:layout_width to match_parent. This will fill up all the available space horizontally.
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/body" />
<EditText android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" />
<Button android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
For Layout file of activity :
<FrameLayout
android:id="#+id/frame1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="130dp"
android:layout_toRightOf="#+id/textView1" >
</FrameLayout>
You can use the property "ems" to change the size.
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
for your text views and edit views try to match_parent instead of wrapping content
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title" />
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>

Categories