I am working with Android Data Binding from activity to layout as a string but its not showing - android

I am sending the string from my activity to the layout that is created as a common layout with data binding but it's not working. I have checked a lot of answers but nothing is working for me.
I want the same thing as the OP wants in following question, but the solution he accepted is not working for me.
Passing string to included layout via data binding not working
following is my layout resume_detail_heading.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="sectionTitle"
type="java.lang.String" />
</data>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardBackgroundColor="#color/app_color_1">
<TextView
android:id="#+id/resume_detail_section_heading"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginVertical="10dp"
android:text="#{sectionTitle}"
android:textAlignment="center"
android:textColor="#color/color_white"
android:textSize="20sp" />
</android.support.v7.widget.CardView>
</layout>
And This is my Activity where I am calling the layout
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/color_white"
>
<data>
<variable
name="sectionTitle"
type="java.lang.String" />
</data>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/availablitycardview"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="5dp"
android:background="#color/color_white">
<TextView
android:id="#+id/availablity"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Available Now"
android:gravity="center"
android:textColor="#color/color_white"
android:textSize="20sp" />
</android.support.v7.widget.CardView>
<include
android:id="#+id/titleRole"
layout="#layout/resume_detail_heading"
app:sectionTitle="#{#string/app_name}" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ListView
android:id="#+id/roles_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:scrollbars="none"></ListView>
</android.support.v7.widget.CardView>
<!--For Skill-->
<include
android:id="#+id/titleSkill"
layout="#layout/resume_detail_heading"
app:sectionTitle="#{`Skill`}" />
...............

Related

ScrollView can host only one direct child and i also have only one child

I have a layout which need to be scrollable.This is a fragment and the fragment hosted on a activity.The ScrollView has only one child which is relativeLayout and the relativeLayout has multiple child.But i still get the error.The error occured when i install and open the screen,after 5 or 6 second,the app is crashed.
This is my layout structure for fragment:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
</data>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable"/>
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/settingsAppBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
/>
<com.google.android.material.button.MaterialButton
android:id="#+id/backButton"
style="#style/back_arrow_button"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.cardview.widget.CardView
>
<LinearLayout
>
<RelativeLayout style="#style/settings_relative_layout_style">
<TextView
/>
<com.google.android.material.imageview.ShapeableImageView
/>
</RelativeLayout>
<View
android:layout_width="match_parent"
/>
<TextView
style="#style/settings_text_style"
/>
<RelativeLayout style="#style/settings_relative_layout_style">
<TextView
/>
<ImageView
/>
</RelativeLayout>
<RelativeLayout style="#style/settings_relative_layout_style">
<TextView
/>
<ImageView
/>
</RelativeLayout>
<View
android:layout_height="1dp"
/>
<TextView
/>
<RelativeLayout style="#style/settings_relative_layout_style">
<TextView
/>
<ImageView
/>
</RelativeLayout>
<RelativeLayout style="#style/settings_relative_layout_style">
<TextView
/>
<ImageView
/>
</RelativeLayout>
<RelativeLayout style="#style/settings_relative_layout_style">
<TextView
/>
<ImageView
/>
</RelativeLayout>
<RelativeLayout style="#style/settings_relative_layout_style">
<TextView
/>
<ImageView
style="#style/settings_image_view_style"
/>
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</ScrollView>
</layout>
This is the layout for Main activity:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.presentations.activity.MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottomMenu"
app:defaultNavHost="true" />
<me.ibrahimsn.lib.SmoothBottomBar
android:visibility="gone"
app:iconSize="#dimen/l"
android:elevation="#dimen/xxxs"
app:iconTintActive="#color/nav_icon_color"
app:iconTint="#D0D0D0"
android:id="#+id/bottomMenu"
android:layout_width="match_parent"
android:layout_height="#dimen/xxxxxxl"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav_menu" />
</RelativeLayout>
</layout>
The error msg:
FATAL EXCEPTION: main Process: ltd.tinkers.example, PID: 10147 java.lang.IllegalStateException: ScrollView can host only one direct child at androidx.core.widget.NestedScrollView.addView(NestedScrollView.java:515) at com.google.android.material.snackbar.BaseTransientBottomBar$SnackbarBaseLayout.addToTargetParent(BaseTransientBottomBar.java:1330) at com.google.android.material.snackbar.BaseTransientBottomBar.showView(BaseTransientBottomBar.java:757) at com.google.android.material.snackbar.BaseTransientBottomBar$1.handleMessage(BaseTransientBottomBar.java:263) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7948) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:603) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I try to use NestedScrollView but problem not fix.I wrap the fragment layout scroll view with FrameLayout which is found from stack overflow answer.But this did not work.

Fragment layout is not Scrolling completely when keyboard opens

I want the layout inside my fragment to scroll completely and place it above the softkeyboard whenever keyboard opens. But the problem is the layout is not even scrolling when i user click on keyboard. It covers up some part of the layout.
I have tried many SO threads already but none of them seems to be working.
Here's the activity layout:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<import type="android.view.View" />
<variable
name="viewModel"
type="com.abc.viewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".home.HomeActivity">
<com.google.android.material.card.MaterialCardView
android:id="#+id/taskBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_minus10sdp"
android:background="#android:color/white"
app:cardCornerRadius="#dimen/_5sdp">
</com.google.android.material.card.MaterialCardView>
<LinearLayout
android:id="#+id/appbar_practice"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryDark"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="#dimen/_10sdp">
</LinearLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</layout>
Here's the fragment layout:
<?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="wrap_content"
android:isScrollContainer="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:animateLayoutChanges="true"
android:background="#drawable/ic_bg_splash"
android:fillViewport="true"
android:paddingBottom="#dimen/_10sdp">
<LinearLayout
android:id="#+id/cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2">
<ImageButton
android:id="#+id/previous"
android:layout_width="#dimen/_30sdp"
android:layout_height="#dimen/_30sdp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/_20sdp"
android:background="#drawable/left"
android:padding="#dimen/_5sdp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2">
<ImageButton
android:id="#+id/next"
android:layout_width="#dimen/_30sdp"
android:layout_height="#dimen/_30sdp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="#dimen/_20sdp"
android:background="#drawable/right" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Manifest:
<activity android:name=".home.MainActivity"
android:screenOrientation="landscape"
android:theme="#style/MaterialThemeHome"></activity>

Values passed to <include> layout is not displayed

I have a included an layout and passing data using app:variable-name but cannot see the results. The variable-name is defined in the layout to be included. Do the way I pass data to the layout incorrect?
<?xml version="1.0" encoding="utf-8"?>
<layout
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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".AboutFragment">
<include
android:id="#+id/dev1"
layout="#layout/include_dev_credit"
app:pic="#{#drawable/dev1}"
app:name="#{#string/dev1}"
app:role="#{#string/dev1}"
/>
</LinearLayout>
</layout>
This is is the layout to be included. It contains one imageview and two text views to be inflated. The data variables have been defined here.
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<data>
<variable
name="name"
type="String"/>
<variable
name="role"
type="String"/>
<variable
name="pic"
type="android.graphics.drawable.Drawable"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:paddingBottom="8dp">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:scaleType="centerCrop"
android:src="#{pic}"/>
<TextView
android:id="#+id/nameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:paddingTop="8dp"
android:text="#{name}"
android:ems="8"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/picView"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/roleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:textAlignment="center"
android:text="#{role}"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_to`enter code here`EndOf="parent"
app:layout_constraintStart_toEndOf="#+id/picView"
app:layout_constraintTop_toBottomOf="#+id/nameView"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

AndroidX RecyclerView row height won't wrap

I've been using the new Androidx libraries and have run into an issue I cannot fix. I am using RecyclerView and just cannot get the row to wrap. It is supposed to do it, and everything I read seems to be that it just works if I cannot get it right. I have used this previously and did not have this issue. I've tried adjusting every setting in both my main layout and the item layout, but nothing seems to affect it. Any help would be appreciated.
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
xmlns:tools="http://schemas.android.com/tools">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cardRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
android:clipToPadding="false"
app:spanCount="4"
android:orientation="vertical"
tools:listitem="#layout/item_card_preview"/>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:liftOnScroll="true">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/white"
app:titleTextColor="#color/colorSecondary" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
item.xml
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="card"
type="com.jibmobile.clashroyaltoolkit.vo.CardPreview"/>
</data>
<ImageView
android:id="#+id/imageView"
image="#{card.name}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:paddingTop="0dp"
android:contentDescription="#{card.displayName}"
tools:src="#drawable/archers" />
OK in my case , in item.xml, the height was given "match_parent". After I converted it into "wrap_content", the recycle view height was expanded according to the number of items. Note that I am using the androidx library as well.
The item.xml code was like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:padding="#dimen/small_padding">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tickred"
android:layout_marginStart="0dp"
android:layout_marginTop="1dp"
android:layout_gravity="top"
android:layout_marginEnd="#dimen/dimen_margin_between_text"/>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="#+id/serviceTv"
android:layout_gravity="top"
android:gravity="top"
app:fontFamily="#font/lato_regular"
android:textColor="#color/black"
android:textSize="#dimen/dimen_text_smallx"/>
</LinearLayout>
I changed the container height to wrap_content and the recycleview takes its height accordingly.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:padding="#dimen/small_padding">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tickred"
android:layout_marginStart="0dp"
android:layout_marginTop="1dp"
android:layout_gravity="top"
android:layout_marginEnd="#dimen/dimen_margin_between_text"/>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="#+id/serviceTv"
android:layout_gravity="top"
android:gravity="top"
app:fontFamily="#font/lato_regular"
android:textColor="#color/black"
android:textSize="#dimen/dimen_text_smallx"/>
</LinearLayout>

NestedScrollView Crash Android [duplicate]

This question already has an answer here:
A scroll view can have only one child Android XML file
(1 answer)
Closed 5 years ago.
Trying to get back coding in android. Why do my program crash when I add another TextView to my XML file?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_comp_analysis"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Enter a complex number below"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST"
/>
</android.support.v4.widget.NestedScrollView>
The XML file is my content file in one of my Android Activities. Probably really basic, but I can't find the mistake.
NestedScrollView should have only one direct child. Add a new Linear/Relative layout as a container or TextViews.
Try this:
<NestedScrollView>
<LinearLayout>
<TextView>
<TextView>
<LinearLayout>
<NestedScrollView>
Update your XML as below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_comp_analysis"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Enter a complex number below"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Try this code : You need to add child under the scroll view , Then only the scroll view will work:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis"
tools:showIn="#layout/activity_comp_analysis">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Enter a complex number below"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_comp_analysis"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Enter a complex number below"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Categories

Resources