getInfoContents not show my custom marker's view (ConstraintLayout) - android

android studio 3.6
I need to show custom view when click on map's marker:
implementation 'com.google.android.gms:play-services-maps:17.0.0'
snippet to show marker info window
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
mMap.setInfoWindowAdapter(object : GoogleMap.InfoWindowAdapter {
override fun getInfoWindow(marker: Marker): View? {
return null
}
override fun getInfoContents(marker: Marker): View? {
val markerLatLng = marker.position
val selectGazStattion =
gazStationsList.first { it.latitude == markerLatLng.latitude && it.longitude == markerLatLng.longitude }
val customView = layoutInflater.inflate(
R.layout.map_marker_info_content_layout, null
)
val textView : TextView = customView.findViewById(R.id.addressValueTextView)
textView.setText(selectGazStattion.address)
return customView
}
})
here map_marker_info_content_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/titleContainerLayout"
android:layout_width="0dp"
android:layout_height="#dimen/min_height"
android:layout_marginStart="#dimen/half_default_margin"
android:layout_marginTop="#dimen/default_margin"
android:layout_marginEnd="#dimen/half_default_margin"
android:background="#drawable/bottom_border_bg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/titleTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/half_default_margin"
android:gravity="center|start"
android:text="Title"
android:textColor="#android:color/black"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/stateTtextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/open"
android:textColor="#android:color/holo_green_light"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/titleTextView"
app:layout_constraintStart_toStartOf="#+id/titleTextView"
app:layout_constraintTop_toBottomOf="#+id/titleTextView" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/containerAgentInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/half_default_margin"
android:background="#drawable/bottom_border_bg"
app:layout_constraintEnd_toEndOf="#+id/titleContainerLayout"
app:layout_constraintStart_toStartOf="#+id/titleContainerLayout"
app:layout_constraintTop_toBottomOf="#+id/titleContainerLayout">
<TextView
android:id="#+id/addressLabelTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/half_default_margin"
android:layout_marginEnd="#dimen/half_default_margin"
android:text="#string/address_colon"
app:layout_constraintEnd_toStartOf="#+id/addressValueTextView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/addressValueTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/addressLabelTextView"
app:layout_constraintTop_toTopOf="#+id/addressLabelTextView" />
<TextView
android:id="#+id/workingHoursLabelTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/half_default_margin"
android:text="#string/working_hours_colon"
app:layout_constraintEnd_toEndOf="#+id/addressLabelTextView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/addressLabelTextView"
app:layout_constraintTop_toBottomOf="#+id/addressLabelTextView" />
<TextView
android:id="#+id/workingHoursValueTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/addressValueTextView"
app:layout_constraintTop_toTopOf="#+id/workingHoursLabelTextView" />
<TextView
android:id="#+id/phoneLabelTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/half_default_margin"
android:text="#string/phone_colon"
app:layout_constraintEnd_toEndOf="#+id/addressLabelTextView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/workingHoursLabelTextView"
app:layout_constraintTop_toBottomOf="#+id/workingHoursLabelTextView" />
<TextView
android:id="#+id/phoneValueTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/addressValueTextView"
app:layout_constraintTop_toTopOf="#+id/phoneLabelTextView" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/containerServices"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/half_default_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/titleContainerLayout"
app:layout_constraintStart_toStartOf="#+id/titleContainerLayout"
app:layout_constraintTop_toBottomOf="#+id/containerAgentInfo">
<TextView
android:id="#+id/servicesTextView"
style="#style/mapMarkerInfoItemLabelTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/half_default_margin"
android:layout_marginEnd="#dimen/half_default_margin"
android:text="#string/services_colon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.yarolegovich.discretescrollview.DiscreteScrollView
android:id="#+id/agetServiceDiscreteScrollView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:dsv_orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/servicesTextView" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
But when I click on marker I get this:
Why not show my custom view?
P.S. If I use LinearLayout then success show info window. But with androidx.constraintlayout.widget.ConstraintLayout not work

Related

Navigating from one fragment to another using Fragment manager in kotlin

I am trying to navigate from one fragment to another using Fragment Manager but the app exits when the button is clicked. I tried a few solutions from the internet but
I am still not able to figure out why. Please help. Thanks in advance!
Groups.kt => The first fragment
package com.example.groupmail
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class Groups : Fragment(){
private lateinit var addGroup : ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_group_list, container, false)
val recyclerview = view.findViewById<RecyclerView>(R.id.group_list)
val layoutManager: RecyclerView.LayoutManager = LinearLayoutManager(activity)
recyclerview.setLayoutManager(layoutManager)
recyclerview.setHasFixedSize(true)
/*Dummy data => Remove Later */
val dummyData = arrayListOf<GroupList>()
dummyData.add(GroupList("group1", R.drawable.ic_settings))
dummyData.add(GroupList("group2", R.drawable.ic_settings))
dummyData.add(GroupList("group3", R.drawable.ic_settings))
dummyData.add(GroupList("group4", R.drawable.ic_settings))
/*End of dummy data */
val adapter = GroupListAdapter(dummyData)
recyclerview.setAdapter(adapter)
addGroup = view.findViewById(R.id.addGroupsbtn)
/* Move to next fragment on button click*/
addGroup.setOnClickListener {
val fragment = AddingGroup()
fragmentManager?.beginTransaction()?.replace(R.id.addgroup,AddingGroup())?.commit()
}
return view
}
}
fragment_adding_group.xml => Layout of the second fragment
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
tools:context=".MainActivity"
android:id="#+id/addgroup">
<TextView
android:id="#+id/title"
android:layout_width="373dp"
android:layout_height="312dp"
android:text="Add a Group"
android:textColor="#000000"
android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.703"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/NameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#636363"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.072"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.858"
tools:ignore="MissingConstraints" />
<EditText
android:id="#+id/group_name"
android:layout_width="339dp"
android:layout_height="48dp"
android:background="#d4d4d4"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20dp"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.361"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.785"
tools:ignore="MissingConstraints,SpeakableTextPresentCheck" />
<TextView
android:id="#+id/EmailLabel"
android:layout_width="283dp"
android:layout_height="234dp"
android:text="Add Member's Email"
android:textColor="#636363"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.175"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.566"
tools:ignore="MissingConstraints" />
<EditText
android:id="#+id/member_email"
android:layout_width="340dp"
android:layout_height="48dp"
android:background="#d4d4d4"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="20dp"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.309"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.644"
tools:ignore="MissingConstraints,SpeakableTextPresentCheck" />
<Button
android:id="#+id/btn_submit"
android:layout_width="337dp"
android:layout_height="48dp"
android:text="Add Group"
android:textAllCaps="false"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.519"
tools:ignore="MissingConstraints" />
<ImageView
android:id="#+id/imageAdd1"
android:layout_width="90dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.884"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.652"
app:srcCompat="#drawable/ic_add_circle"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/MessageLabel"
android:layout_width="293dp"
android:layout_height="23dp"
android:text="Group limit is upto 7 only!!"
android:textColor="#636363"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.454"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.588"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/MemberTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Members"
android:textColor="#000000"
android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.056"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintVertical_bias="0.447"
tools:ignore="MissingConstraints" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/memberRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:ignore="MissingConstraints"
tools:itemCount="5"
tools:listitem="#layout/fragment_memberlist_card" />
</androidx.constraintlayout.widget.ConstraintLayout>
Error displayed :

Recyclerview items not covering entire screen

I am struggling with a bug for a couple of days. For some reason, my recycler view items don't cover the entire screen.
Here is the code :
feed_fragment.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="viewModel"
type="com.example.bookally.ui.posts.feed.FeedViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme">
<TextView
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/feed"
android:textSize="20sp" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/feeds_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/white"
android:clipToPadding="false"
android:paddingLeft="16dp"
android:paddingTop="28dp"
android:paddingRight="16dp"
android:paddingBottom="28dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
tools:listitem="#layout/item_feed" />
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_baseline_add_24"
android:onClick="#{() -> viewModel.addPosts()}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:contentDescription="#string/create_post" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
item_feed.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="post"
type="com.example.bookally.firebase.PostContent" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="#drawable/post_border">
<ImageView
android:id="#+id/author_profile_picture"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:contentDescription="#string/user_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:setProfilePhoto="#{post.authorImageUrl}" />
<TextView
android:id="#+id/author_name"
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="#{post.author}"
android:textSize="18sp"
app:layout_constraintStart_toEndOf="#+id/author_profile_picture"
app:layout_constraintTop_toTopOf="parent"
tools:text="Iqbal Singh" />
<TextView
android:id="#+id/username"
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="4dp"
android:text="#{post.username}"
android:textColor="#color/colorGrey"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="#+id/author_profile_picture"
app:layout_constraintTop_toBottomOf="#+id/author_name"
tools:text="\#just_another_boy" />
<TextView
android:id="#+id/post_content"
style="#style/SubHeading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:gravity="start"
android:text="#{post.content}"
android:textAlignment="viewStart"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/username"
tools:text="Anything random ...." />
<ImageButton
android:id="#+id/like_btn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="#android:color/transparent"
android:contentDescription="#string/likes"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/post_image"
app:likeIcon="#{post.likedBy}" />
<TextView
android:id="#+id/likes_no"
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="#+id/like_btn"
app:layout_constraintStart_toEndOf="#+id/like_btn"
app:layout_constraintTop_toTopOf="#+id/like_btn"
app:likesText="#{post.likes}"
tools:text="7 Likes" />
<TextView
android:id="#+id/comments_no"
style="#style/MainHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:textSize="16sp"
app:commentsText="#{post.commentsNumber}"
app:layout_constraintStart_toEndOf="#+id/comment_btn"
app:layout_constraintTop_toTopOf="#+id/comment_btn"
tools:text="0 Comments" />
<ImageButton
android:id="#+id/comment_btn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="#android:color/transparent"
android:contentDescription="#string/comment"
android:src="#drawable/ic_comment"
app:layout_constraintStart_toEndOf="#+id/likes_no"
app:layout_constraintTop_toBottomOf="#+id/post_image" />
<ImageButton
android:id="#+id/save_post_btn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:background="#android:color/transparent"
android:contentDescription="#string/save_post"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/post_image"
app:saveIcon="#{post.savedBy}" />
<ImageButton
android:id="#+id/add_friend_btn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:background="#android:color/transparent"
android:contentDescription="#string/add_friend"
android:src="#drawable/ic_add_friend"
app:layout_constraintBottom_toBottomOf="#+id/username"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/author_name" />
<ImageView
android:id="#+id/post_image"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:contentDescription="#string/post_imageview_content_description"
app:layout_constraintBottom_toTopOf="#+id/comments_no"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/post_content"
app:layout_constraintVertical_bias="0.0"
app:loadImagesFromFirebase="#{post.postImageUrl}" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
FeedAdapter
class FeedAdapter(private val onClickListener: ClickListener) : PagingDataAdapter<Post, FeedAdapter.FeedViewHolder>(
DiffCallback
) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedViewHolder {
return FeedViewHolder(ItemFeedBinding.inflate(LayoutInflater.from(parent.context)))
}
override fun onBindViewHolder(holder: FeedViewHolder, position: Int) {
val post = getItem(position)
holder.itemView.findViewById<ImageButton>(R.id.like_btn).setOnClickListener { if (post != null) onClickListener.onLikeClicked(post) }
holder.itemView.findViewById<ImageButton>(R.id.comment_btn).setOnClickListener { if (post != null) onClickListener.onCommentClicked(post) }
holder.itemView.findViewById<ImageButton>(R.id.save_post_btn).setOnClickListener { if (post != null) onClickListener.onSavePostClicked(post) }
holder.itemView.findViewById<ImageButton>(R.id.add_friend_btn).setOnClickListener { if (post != null) onClickListener.onAddFriendClicked(post) }
if (post != null) holder.bind(post.postContent)
}
class FeedViewHolder(private val binding : ItemFeedBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(feed: PostContent) {
binding.post = feed
binding.executePendingBindings()
}
}
In the design tab, everything looks fine :
However, the problem arises in real devices :
However, if I add a view like this, the items cover the entire screen :
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/like_btn" />
Any help would be really appreciated. Thanks in advance !!
I believe the problem is here:
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedViewHolder {
return FeedViewHolder(ItemFeedBinding.inflate(LayoutInflater.from(parent.context)))
}
Because you are calling the overload of inflate() that does not specify a parent view, your item view's layout params are being ignored. Change it to this instead:
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeedViewHolder {
return FeedViewHolder(ItemFeedBinding.inflate(LayoutInflater.from(parent.context), parent, false))
}
you problem is
android:layout_height="wrap_content"
<TextView
android:id="#+id/post_content"
style="#style/SubHeading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:gravity="start"
android:text="#{post.content}"
android:textAlignment="viewStart"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/username"
tools:text="Anything random ...." />
you must set fixedHeight or use maxLines and set width to match_parent
also remove this line android:textAlignment="viewStart"

No view found for id for fragment InspectionDetailsFragment

I have the following XML
<?xml version="1.0" encoding="utf-8"?>
<layout>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fragment_inspection_details_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="#dimen/size_0dp"
android:layout_height="#dimen/size_0dp"
app:layout_constraintBottom_toTopOf="#+id/fragment_inspection_details_buttons_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/fragment_inspection_details_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:text="#string/details"
android:textAllCaps="true"
android:textColor="#color/gold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="#dimen/size_0dp"
android:layout_height="1dp"
android:layout_margin="#dimen/size_16dp"
android:background="#color/lightGray"
app:layout_constraintBottom_toBottomOf="#+id/fragment_inspection_details_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/fragment_inspection_details_title"
app:layout_constraintTop_toTopOf="#+id/fragment_inspection_details_title" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_status_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_title">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_status_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/status" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_start_time_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_status_til">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_start_time_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/start_time" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_end_time_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_start_time_til">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_end_time_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/end_time" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/fragment_inspection_details_desc_time_til"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_end_time_til">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_desc_time_tie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:hint="#string/description" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/fragment_inspection_details_handling_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:text="#string/handling"
android:textAllCaps="true"
android:textColor="#color/gold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_desc_time_til" />
<View
android:layout_width="#dimen/size_0dp"
android:layout_height="1dp"
android:layout_margin="#dimen/size_16dp"
android:background="#color/lightGray"
app:layout_constraintBottom_toBottomOf="#+id/fragment_inspection_details_handling_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/fragment_inspection_details_handling_title"
app:layout_constraintTop_toTopOf="#+id/fragment_inspection_details_handling_title" />
<TextView
android:id="#+id/fragment_inspection_details_outcome_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:text="#string/outcome"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_handling_title" />
<Spinner
android:id="#+id/fragment_inspection_details_outcome_spinner"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/size_8dp"
android:layout_marginEnd="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_outcome_title" />
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/size_16dp"
android:layout_marginEnd="#dimen/size_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragment_inspection_details_outcome_spinner">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/fragment_inspection_details_outcome_report_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Outcome report" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<LinearLayout
android:id="#+id/fragment_inspection_details_buttons_container"
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.appcompat.widget.AppCompatButton
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:layout_weight="1"
android:background="#drawable/white_background_gray_rounded_border"
android:text="#string/save"
android:textAllCaps="false" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="#dimen/size_0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_16dp"
android:layout_weight="1"
android:background="#drawable/white_background_gray_rounded_border"
android:text="#string/handle"
android:textAllCaps="false" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
and the following code -
class InspectionDetailsFragment : Fragment() {
companion object {
fun newInstance(inspection: Inspection): InspectionDetailsFragment {
val inspectionDetailsFragment = InspectionDetailsFragment()
val bundle = Bundle()
bundle.putParcelable(Constants.INSPECTION, inspection)
inspectionDetailsFragment.arguments = bundle
return inspectionDetailsFragment
}
}
...
...
}
//Inside another Fragment
changeFragment(
parentFragmentManager, R.id.fragment_inspection_details_root,
InspectionDetailsFragment.newInstance(inspection), true
)
// Change fragment extension function to handle navigation easily
#SuppressLint("PrivateResource")
fun changeFragment(fragmentManager: FragmentManager?, #IdRes containerId: Int, fragment: Fragment?, addToBackStack: Boolean = false) {
if (fragmentManager == null) return
val fragmentTransaction = fragmentManager.beginTransaction()
if (addToBackStack) fragmentTransaction.addToBackStack(null)
/*fragmentTransaction.setCustomAnimations(
R.anim.abc_fade_in,
R.anim.abc_shrink_fade_out_from_bottom,
R.anim.abc_grow_fade_in_from_bottom,
R.anim.abc_popup_exit
)*/
fragment?.let {
fragmentTransaction
.replace(containerId, it, it::class.java.simpleName)
.commit()
}
}
For some reason when trying to navigate to the InspectionDetailsFragment the app crashes with the No view found for id 0x7f0900df (com.supercom.myapplication:id/fragment_inspection_details_root) for fragment InspectionDetailsFragment I really have no idea what's wrong, I tried to look up but it seems like I am doing everything correct.
The InspectionDetailsFragment used to have a container fragment for it but I deleted it, maybe that is related to the issue I am getting?

Manage RadioButton without RadioGroup (Click on ParentView)

I have created one XML with 4 CardView contains 4 RadioButton and other layouts as follow:
fragment_list_of_transport.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<android.support.v4.widget.NestedScrollView 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.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:id="#+id/parent_card_1"
android:layout_width="0dp"
android:background="?attr/selectableItemBackground"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_1"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_1" />
<ImageView
android:id="#+id/image_truck_1"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_1"
app:layout_constraintStart_toEndOf="#+id/radio_button_1"
app:layout_constraintTop_toTopOf="#+id/title_text_view_1"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_1"
app:layout_constraintTop_toBottomOf="#+id/image_view_1" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_text_view_1"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/parent_card_2"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/parent_card_1">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_2"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_2" />
<ImageView
android:id="#+id/image_truck_2"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_2"
app:layout_constraintStart_toEndOf="#+id/radio_button_2"
app:layout_constraintTop_toTopOf="#+id/title_text_view_2"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_2"
app:layout_constraintTop_toBottomOf="#+id/image_view_2" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_text_view_2"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:id="#+id/parent_card_3"
android:layout_width="0dp"
android:background="?attr/selectableItemBackground"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/parent_card_2">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_3"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_3" />
<ImageView
android:id="#+id/image_truck_3"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_3"
app:layout_constraintStart_toEndOf="#+id/radio_button_3"
app:layout_constraintTop_toTopOf="#+id/title_text_view_3"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_3"
app:layout_constraintTop_toBottomOf="#+id/image_view_3" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_text_view_3"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:id="#+id/parent_card_4"
android:background="?attr/selectableItemBackground"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
android:layout_marginBottom="#dimen/_10sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/parent_card_3">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_4"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_4" />
<ImageView
android:id="#+id/image_truck_4"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_4"
app:layout_constraintStart_toEndOf="#+id/radio_button_4"
app:layout_constraintTop_toTopOf="#+id/title_text_view_4"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_4"
app:layout_constraintTop_toBottomOf="#+id/image_view_4" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_text_view_4"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</layout>
Output:
I want to manage RadioButton on click of both CardView and RadioButton , I have used following code:
/**
* A simple {#link Fragment} subclass.
*/
public class FragmentListTransport extends Fragment implements View.OnClickListener {
FragmentListOfTransportBinding mBinding;
public FragmentListTransport() {
// Required empty public constructor
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_list_of_transport, container, false);
mBinding.parentCard1.setOnClickListener(this);
mBinding.parentCard2.setOnClickListener(this);
mBinding.parentCard3.setOnClickListener(this);
mBinding.parentCard4.setOnClickListener(this);
return mBinding.getRoot();
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.parent_card_1:
mBinding.radioButton1.setChecked(true);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(false);
break;
case R.id.parent_card_2:
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(true);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(false);
break;
case R.id.parent_card_3:
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(true);
mBinding.radioButton4.setChecked(false);
break;
case R.id.parent_card_4:
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(true);
break;
}
}
}
Is there any best way to manage it?
I don't easiest way then following (If you have easy way then I will accept it.):
/**
* A simple {#link Fragment} subclass.
*/
public class FragmentListTransport extends Fragment implements View.OnClickListener {
FragmentListOfTransportBinding mBinding;
public FragmentListTransport() {
// Required empty public constructor
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_list_of_transport, container, false);
mBinding.parentCard1.setOnClickListener(this);
mBinding.parentCard2.setOnClickListener(this);
mBinding.parentCard3.setOnClickListener(this);
mBinding.parentCard4.setOnClickListener(this);
mBinding.radioButton1.setOnClickListener(this);
mBinding.radioButton2.setOnClickListener(this);
mBinding.radioButton3.setOnClickListener(this);
mBinding.radioButton4.setOnClickListener(this);
return mBinding.getRoot();
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.parent_card_1:
case R.id.radio_button_1:
clickedRadioButton(mBinding.radioButton1);
break;
case R.id.parent_card_2:
case R.id.radio_button_2:
clickedRadioButton(mBinding.radioButton2);
break;
case R.id.parent_card_3:
case R.id.radio_button_3:
clickedRadioButton(mBinding.radioButton3);
break;
case R.id.parent_card_4:
case R.id.radio_button_4:
clickedRadioButton(mBinding.radioButton4);
break;
}
}
private void clickedRadioButton(RadioButton radioButton) {
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(false);
radioButton.setChecked(true);
}
}
If anyone has easiest way then this, please post answer. I will accept.

layout is not showing up

I'm trying to create a layout for my Fragment . Here is my xml layout.
Fragment_profil.xml
<FrameLayout 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"
tools:context="com.example.boby.srsly.ProfilFragment">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.517"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.027">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/fullnametext"
android:layout_width="144dp"
android:layout_height="18dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="64dp"
android:text="fullnametext"
app:layout_constraintBottom_toTopOf="#+id/notelptext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.716"
app:layout_constraintStart_toEndOf="#+id/fullnameLabel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<TextView
android:id="#+id/fullnameLabel"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="76dp"
android:text="Fullname"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView4"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="64dp"
android:text="No Telp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
app:layout_constraintEnd_toStartOf="#+id/notelptext" />
<TextView
android:id="#+id/notelptext"
android:layout_width="144dp"
android:layout_height="20dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="28dp"
android:text="notelp"
app:layout_constraintBottom_toTopOf="#+id/deskripsitxt"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/textView6"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginEnd="60dp"
android:text="Deskripsi"
app:layout_constraintEnd_toStartOf="#+id/deskripsitxt"
tools:layout_editor_absoluteY="180dp" />
<TextView
android:id="#+id/deskripsitxt"
android:layout_width="144dp"
android:layout_height="63dp"
android:layout_marginBottom="252dp"
android:layout_marginEnd="28dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</FrameLayout>
But, when i run it i only see white background, i mean because this is bottomnavigationview i only can see the navigation from what i write above. How can i fix it, is there something missing ? Thanks in advance and sorry for my bad english.
Here is my ProfilFragment.java
public class ProfilFragment extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_profil, container, false);
SharedPreferences mPrefs = this.getActivity().getSharedPreferences("userinfoafterlogin", MODE_PRIVATE); //add key
String response = mPrefs.getString("userinfo", null);
try{
JSONObject json = new JSONObject(response);
json = (JSONObject)json.get("nameValuePairs");
json = (JSONObject)json.get("userData");
json = (JSONObject)json.get("nameValuePairs");
String fullname = (String)json.get("fullname");
String phone = (String)json.get("phone");
String desc = (String)json.get("Deskripsi");
TextView labelfullname = (TextView)v.findViewById(R.id.fullnametext);
TextView labeltelp = (TextView)v.findViewById(R.id.notelptext);
TextView labeldesc = (TextView)v.findViewById(R.id.deskripsitxt);
labelfullname.setText(fullname);
labeltelp.setText(phone);
labeldesc.setText(desc);
return v;
}catch (JSONException e) {
Log.e("MYAPP", "unexpected JSON exception", e);
return v;
}
}
}
Try this
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.517"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.027">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/fullnametext"
android:layout_width="144dp"
android:layout_height="18dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="64dp"
android:text="fullnametext"
app:layout_constraintBottom_toTopOf="#+id/notelptext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.716"
app:layout_constraintStart_toEndOf="#+id/fullnameLabel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<TextView
android:id="#+id/fullnameLabel"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="76dp"
android:text="Fullname"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView4"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="64dp"
android:text="No Telp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
app:layout_constraintEnd_toStartOf="#+id/notelptext" />
<TextView
android:id="#+id/notelptext"
android:layout_width="144dp"
android:layout_height="20dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="28dp"
android:text="notelp"
app:layout_constraintBottom_toTopOf="#+id/deskripsitxt"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/textView6"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginEnd="60dp"
android:text="Deskripsi"
app:layout_constraintEnd_toStartOf="#+id/deskripsitxt"
tools:layout_editor_absoluteY="180dp" />
<TextView
android:id="#+id/deskripsitxt"
android:layout_width="144dp"
android:layout_height="63dp"
android:layout_marginBottom="252dp"
android:layout_marginEnd="28dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
OUTPUT

Categories

Resources