White space between each item in recycler view - android

I'm using Firebase Recycler in my app and I implemented the code in my fragment. The data loads fine but when I scroll to end of list the items gets white spaces between each and that spaces clears only when changed from one activity to other.
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="55dp">
<androidx.appcompat.widget.Toolbar
android:id="#+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<TextView
android:id="#+id/map_view"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:drawableStart="#drawable/ic_location_on_black_24dp"
android:drawablePadding="10dp"
android:ellipsize="end"
android:fontFamily="#font/roboto_medium"
android:gravity="center"
android:maxLines="1"
android:padding="5dp"
android:text="#string/text1" />
</androidx.appcompat.widget.Toolbar>
<androidx.cardview.widget.CardView
app:cardCornerRadius="10dp"
android:layout_margin="14dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.smarteist.autoimageslider.SliderView
android:id="#+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="200dp"
app:sliderAnimationDuration="5000"
app:sliderAutoCycleEnabled="true"
app:sliderIndicatorAnimationDuration="5000"
app:sliderIndicatorGravity="center_horizontal|bottom"
app:sliderIndicatorMargin="15dp"
app:sliderIndicatorOrientation="horizontal"
app:sliderIndicatorPadding="3dp"
app:sliderIndicatorRadius="1dp"
app:sliderIndicatorSelectedColor="#5A5A5A"
app:sliderIndicatorUnselectedColor="#FFF"
app:sliderScrollTimeInSec="3"
app:sliderStartAutoCycle="true" />
</androidx.cardview.widget.CardView>
<RadioGroup
android:id="#+id/layout_change_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<RadioButton
android:id="#+id/btn_for_list1"
android:layout_width="150dp"
android:gravity="center"
android:layout_height="30dp"
android:background="#drawable/radio_flat_selector"
android:button="#android:color/transparent"
android:checked="true"
android:text="Home Services"
android:textColor="#color/radio_flat_text_selector" />
<RadioButton
android:id="#+id/btn_for_list2"
android:gravity="center"
android:layout_width="150dp"
android:layout_height="30dp"
android:background="#drawable/radio_flat_selector"
android:button="#android:color/transparent"
android:text="Home Improvements"
android:textColor="#color/radio_flat_text_selector" />
</RadioGroup>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/main_list1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="15dp"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/main_list2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="15dp"/>
</RelativeLayout>
</LinearLayout>
My Adapter Code:
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.coderedinnovations.allioservices.R;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
public class MainList1_Adapter extends FirebaseRecyclerAdapter<MainList1, MainList1_Adapter.MainList1_Holder> {
public MainList1_Adapter(#NonNull FirebaseRecyclerOptions<MainList1> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull MainList1_Holder holder, int position, #NonNull MainList1 model) {
holder.heading_view.setText(model.getTitle());
holder.desc_view.setText(model.getDescription());
holder.offer_view.setText(model.getOffer());
Glide.with(holder.image_view.getContext())
.load(model.getImageLink())
.into(holder.image_view);
}
#NonNull
#Override
public MainList1_Holder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.main_item_card, parent, false);
return new MainList1_Holder(view);
}
class MainList1_Holder extends RecyclerView.ViewHolder{
TextView heading_view, desc_view, offer_view;
ImageView image_view;
public MainList1_Holder(#NonNull View itemView) {
super(itemView);
heading_view = itemView.findViewById(R.id.item_heading);
desc_view = itemView.findViewById(R.id.item_description);
offer_view = itemView.findViewById(R.id.item_offer);
image_view = itemView.findViewById(R.id.item_image);
}
}
}
Watch this video that will clear explain my problem.
Video Link

Thanks for everyone who tried to answer my question. I just made a small mistake which gave the white spaces between each item.
In the Parent layout of item. I added
android:layout_height:"match_parent"
instead of wrap_content and that made the error.

Related

ViewPager inside MotionLayout not showing items

I implemented a viewPager inside my MotionLayout view, and created the Adapter and set the adapter.
Here is the MotionLayout view:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout 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/bottom_component"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#drawable/bottom_sheet_bg"
android:clickable="true"
android:elevation="10dp"
android:minHeight="#dimen/_290sdp"
app:behavior_hideable="true"
app:behavior_peekHeight="#dimen/_124sdp"
app:layoutDescription="#xml/bottom_sheet_scene"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<View
android:id="#+id/slider"
android:layout_width="50dp"
android:layout_height="4dp"
android:layout_marginTop="#dimen/_4sdp"
android:background="#drawable/slider_bg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/placeName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_18sdp"
android:layout_marginTop="#dimen/_5sdp"
android:layout_marginEnd="#dimen/_8sdp"
android:fontFamily="#font/janna_bold"
android:gravity="start|center_vertical"
android:textColor="#464954"
android:textSize="#dimen/_15sdp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="#id/threeDots"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/slider"
tools:text="Irsal Gas Station" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/placeLocation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_5sdp"
android:fontFamily="#font/janna_regular"
android:text="Ramallah and Al Bireh - Al Irsal"
android:textColor="#B3B3C6"
android:textSize="#dimen/_12sdp"
app:layout_constraintEnd_toEndOf="#id/threeDots"
app:layout_constraintStart_toStartOf="#id/placeName"
app:layout_constraintTop_toBottomOf="#id/placeName" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/threeDots"
android:layout_width="#dimen/_20sdp"
android:layout_height="#dimen/_24sdp"
android:layout_marginEnd="#dimen/_18sdp"
android:tint="#color/blueText"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/placeName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#id/placeName"
app:srcCompat="#drawable/ic_three_dots" />
<LinearLayout
android:id="#+id/routesContainer"
android:layout_width="match_parent"
android:layout_height="#dimen/_70sdp"
android:layout_marginTop="#dimen/_7sdp"
app:layout_constraintTop_toBottomOf="#id/placeLocation">
<androidx.viewpager.widget.ViewPager
android:id="#+id/routes"
android:layout_width="match_parent"
android:background="#EEEEEE"
android:elevation="10dp"
android:layout_height="match_parent" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/addedStop"
android:layout_width="#dimen/_18sdp"
android:layout_height="#dimen/_18sdp"
android:visibility="invisible"
app:layout_constraintStart_toStartOf="#id/routes"
app:layout_constraintTop_toBottomOf="#id/routes"
app:srcCompat="#drawable/ic_plus" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/stops"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/janna_regular"
android:gravity="center_vertical"
android:text="0 Stops"
android:textColor="#464954"
android:textSize="#dimen/_11sdp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/addedStop"
app:layout_constraintStart_toEndOf="#id/addedStop"
app:layout_constraintTop_toTopOf="#id/addedStop" />
<LinearLayout
android:id="#+id/actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_9sdp"
android:orientation="horizontal"
android:paddingVertical="10dp"
android:weightSum="4"
app:layout_constraintTop_toBottomOf="#id/addedStop">
<com.ideal.doroob.custom.ActionButton
android:id="#+id/addStop"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:icon="#drawable/ic_addstop"
app:title="#string/AddStop" />
<com.ideal.doroob.custom.ActionButton
android:id="#+id/share"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:icon="#drawable/ic_share"
app:title="#string/Share" />
<com.ideal.doroob.custom.ActionButton
android:id="#+id/overview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:icon="#drawable/ic_overview"
app:title="#string/Overview" />
<com.ideal.doroob.custom.ActionButton
android:id="#+id/addToFavorite"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:icon="#drawable/ic_favorite"
app:title="#string/Favorite" />
</LinearLayout>
<LinearLayout
android:id="#+id/button_sticky"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_height="#dimen/_30sdp"
android:layout_marginEnd="#dimen/_3sdp"
android:layout_weight="1"
android:background="#drawable/button_bg"
android:fontFamily="#font/janna_regular"
android:gravity="center"
android:text="#string/cancel"
android:textColor="#color/white"
android:textSize="#dimen/_12sdp" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/startNavigation"
android:layout_width="0dp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="#dimen/_3sdp"
android:layout_weight="2"
android:background="#drawable/button_bg"
android:backgroundTint="#7ED321"
android:fontFamily="#font/janna_bold"
android:gravity="center"
android:text="#string/go"
android:textColor="#color/white"
android:textSize="#dimen/_12sdp" />
</LinearLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>
And the adapter is:
package com.ideal.doroob.adapters;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import com.ideal.doroob.data.RouteDetails;
import com.ideal.doroob.databinding.RouteTypeItemBinding;
import java.util.List;
public class RoutesAdapter extends PagerAdapter {
List<RouteDetails> routeDetailsList;
public RoutesAdapter(List<RouteDetails> routeDetails) {
this.routeDetailsList = routeDetails;
}
#Override
public int getCount() {
return 3;
}
#Override
public boolean isViewFromObject(#NonNull View view, #NonNull Object object) {
return view == object;
}
#NonNull
#Override
public Object instantiateItem(#NonNull ViewGroup container, int position) {
RouteDetails routeDetails = routeDetailsList.get(position);
RouteTypeItemBinding binding = RouteTypeItemBinding.inflate(
LayoutInflater.from(container.getContext()));
binding.distance.setText(routeDetails.getDistance() + " " + routeDetails.getUnit());
binding.time.setText(routeDetails.getHours() + ":" + routeDetails.getMinutes());
// ViewPager.LayoutParams params = new ViewPager.LayoutParams();
// params.width = MATCH_PARENT;
// params.height = MATCH_PARENT;
// binding.getRoot().setLayoutParams(params);
container.addView(binding.getRoot(), 0);
return binding.getRoot();
}
#Override
public void destroyItem(#NonNull ViewGroup container, int position, #NonNull Object object) {
container.removeView((View) object);
}
public void replaceRoutes(List<RouteDetails> details) {
routeDetailsList.clear();
routeDetailsList.addAll(details);
}
}
The view pager is shown but the items are not shown inside the view pager.
I checked the layout inspector and the views are added to the view pager, but they are not showing in the UI
I tried to add the view pager inside my activity and it worked well, so I guess the issue is in the MotionLayout.
Any idea ?

Recycler View is Not Displaying

Issue: Recycler View is not displaying. There is no error logged. The page is just blank. I did attempt to look at other similar Recycler View issues, but I have not been able to figure out the problem. I played around with the layout to make sure views were not overlapping but that did not fix the issue. I also looked through the java file but cannot find anything wrong with it. Any help will be appreciated. Thank you!
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Personal_Wall"
tools:openDrawer="end">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/coordinator_layout"
android:layout_width="match_parent"
android:background="#ffff"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
elevation="4dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#ffff"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<ImageView
android:id="#+id/splashd_logo_button"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_gravity="right"
android:paddingRight="10dp"
android:src="#drawable/new_splashd_logo_black"
android:text="hapana_button" />
</androidx.appcompat.widget.Toolbar>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="#+id/fragment-containter2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/edit_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="245dp"
android:layout_marginTop="250dp"
android:elevation="6dp"
android:background="#color/fui_transparent"
app:srcCompat="#drawable/ic_camera_icon" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_place_holder"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="95dp"
android:elevation="4dp"
android:src="#drawable/grey_oval"
app:civ_border_color="#fff"
app:civ_border_width="5dp" />
<androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
card_view:cardBackgroundColor="#fff"
card_view:cardCornerRadius="8dp">
<ImageView
android:id="#+id/temporary_banner_personal_wall"
android:layout_width="380dp"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:srcCompat="#drawable/roundec_corner_rectangle_grey" />
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/personal_wall_text_first_name"
android:layout_width="193dp"
android:layout_height="wrap_content"
android:layout_marginLeft="158dp"
android:layout_marginTop="310dp"
android:layout_marginRight="50dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:inputType="textPersonName"
android:text="First"
android:textColor="#000"
android:textSize="30dp" />
<TextView
android:id="#+id/personal_wall_text_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="210dp"
android:layout_marginTop="310dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:inputType="textPersonName"
android:text="Last"
android:textColor="#000"
android:textSize="30dp" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/small_grey_circle"
android:layout_width="78dp"
android:layout_height="52dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="408dp"
android:src="#drawable/small_grey_circle" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current Location: Washington D.C."
android:textSize="18dp"
android:textColor="#000"
android:fontFamily="#font/roboto_medium"
android:layout_marginTop="360dp"
android:layout_gravity="center_horizontal"
android:drawableLeft="#drawable/ic_profile_location_on_black_24dp"
>
</TextView>
<ImageView
android:id="#+id/personal_wall_post_something_box"
android:layout_width="290dp"
android:layout_height="69dp"
android:layout_marginLeft="95dp"
android:layout_marginTop="398dp"
android:src="#drawable/make_a_splash_oval" />
<TextView
android:id="#+id/assists_count"
android:layout_width="73dp"
android:layout_height="38dp"
android:layout_marginLeft="45dp"
android:layout_marginTop="550dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_light"
android:text="Assists"
android:textColor="#000"
android:textSize="15dp"
android:textAlignment="center"/>
<TextView
android:id="#+id/assists_count_actual_number"
android:layout_width="73dp"
android:layout_height="38dp"
android:layout_marginLeft="45dp"
android:layout_marginTop="515dp"
android:textAlignment="center"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:text="3"
android:textColor="#000"
android:textSize="22dp" />
<TextView
android:id="#+id/followers_count"
android:layout_width="102dp"
android:layout_height="39dp"
android:layout_marginLeft="143dp"
android:layout_marginTop="550dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_light"
android:text="Followers"
android:textColor="#000"
android:textSize="15dp"
android:textAlignment="center"/>
<TextView
android:id="#+id/followers_count_actual_number"
android:layout_width="102dp"
android:layout_height="39dp"
android:layout_marginLeft="144dp"
android:layout_marginTop="515dp"
android:textAlignment="center"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:text="2"
android:textColor="#000"
android:textSize="22dp" />
<TextView
android:id="#+id/splash_count"
android:layout_width="102dp"
android:layout_height="39dp"
android:layout_marginLeft="250dp"
android:layout_marginTop="550dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:fontFamily="#font/roboto_light"
android:text="Splashes"
android:textColor="#000"
android:textSize="15dp"
android:textAlignment="center"/>
<TextView
android:id="#+id/splash_count_actual_number"
android:layout_width="102dp"
android:layout_height="39dp"
android:textAlignment="center"
android:layout_marginLeft="250dp"
android:layout_marginTop="515dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:text="5"
android:textColor="#000"
android:textSize="22dp" />
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_marginTop="590dp"
android:background="#android:color/darker_gray" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="488dp"
android:background="#E8E8E8" />
<TextView
android:id="#+id/testing_scrollview"
android:layout_width="102dp"
android:layout_height="39dp"
android:layout_marginLeft="293dp"
android:layout_marginTop="1400dp"
android:layout_weight="0.5"
android:fontFamily="#font/roboto_light"
android:text="TEST"
android:textColor="#000"
android:layout_marginBottom="120dp"
android:textSize="20dp"
android:textAlignment="center"/>
</FrameLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_post_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="700dp"
android:layout_above="#+id/fragment_container_3">
</androidx.recyclerview.widget.RecyclerView>
<FrameLayout
android:id="#+id/fragment_container_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Main content -->
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:itemIconTint="#color/bottom_navigation_selected_color"
app:itemTextColor="#color/bottom_navigation_selected_color"
app:labelVisibilityMode="unlabeled"
app:menu="#menu/bottom_navigation_menu"
app:itemIconSize="#dimen/bottom_navigation_icon_size"
/>
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
---------------------------------------------------------
package com.example.updatedhapana1;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.squareup.picasso.Picasso;
import com.theartofdev.edmodo.cropper.CropImage;
import com.theartofdev.edmodo.cropper.CropImageView;
import de.hdodenhof.circleimageview.CircleImageView;
import static com.example.updatedhapana1.Personal_Wall_Edit.Gallery_Pick2;
public class Personal_Wall extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
Window window;
private DrawerLayout drawer;
private Bitmap bitmap;
private Uri uri;
private RecyclerView postList; //TRYING RECYCLER VIEW AGAIN AHHHHHHHHHH!
private String currentUserID;
private DatabaseReference UsersReference;
private CircleImageView profile_image;
private StorageReference UserProfileImageRef;
private FirebaseAuth mAuth;
private ImageView post_question;
private ImageButton edit_profile;
private DatabaseReference mDatabaseRef;
private ImageView banner_view;
private ImageButton splash_gallery;
FirebaseUser currentUser;
TextView mfirstname;
TextView mlastname;
TextView firstname_for_main_profile;
TextView lastname_for_main_profile;
NavigationView mNavigationView;
CircleImageView m_nav_header_profile_image;
CircleImageView profile_placeholder_personal_wall;
CircleImageView little_circle_personal_wall;
FirebaseDatabase mfirebaseDatabase;
final static int Gallery_Pick = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_personal__wall);
little_circle_personal_wall = findViewById(R.id.small_grey_circle); //this is to bring in the profile picture from the database
//////This change the status bar color and the status bar text color. I wanted the status bar to be white.//////////
if (Build.VERSION.SDK_INT > 21) {
window = this.getWindow();
window.setStatusBarColor(this.getResources().getColor(R.color.white));
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);// set status text dark
}
//////This change the status bar color and the status bar text color. I wanted the status bar to be white.//////////
mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
UsersReference = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);
UserProfileImageRef = FirebaseStorage.getInstance().getReference().child("Profile Images");
profile_image = findViewById(R.id.profile_place_holder_edit);
mDatabaseRef = FirebaseDatabase.getInstance().getReference("uploads");
profile_placeholder_personal_wall = findViewById(R.id.profile_place_holder);
banner_view = findViewById(R.id.temporary_banner_personal_wall);
//RECYCLERVIEW//
postList = (RecyclerView) findViewById(R.id.recycler_view_post_list);
postList.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
postList.setLayoutManager(linearLayoutManager);
//RECYCLERVIEW//
----------------------------------------------------
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions<Posts> options =
new FirebaseRecyclerOptions.Builder<Posts>()
.setQuery(UsersReference, Posts.class)
.build();
FirebaseRecyclerAdapter<Posts,FindPostsViewHolder> adapter =
new FirebaseRecyclerAdapter<Posts, FindPostsViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull FindPostsViewHolder findPostsViewHolder, int i, #NonNull Posts posts)
{
findPostsViewHolder.first_name.setText(posts.getFirst_name());
findPostsViewHolder.last_name.setText(posts.getLast_name());
findPostsViewHolder.post_date.setText(posts.getPost_date());
findPostsViewHolder.post_body_text.setText(posts.getPost_body_text());
}
#NonNull
#Override
public FindPostsViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.post_layout_2, viewGroup, false);
FindPostsViewHolder viewHolder = new FindPostsViewHolder(view);
return viewHolder;
}
};
postList.setAdapter(adapter);
adapter.startListening();
}
public static class FindPostsViewHolder extends RecyclerView.ViewHolder
{
TextView first_name, last_name, post_body_text, post_date;
public FindPostsViewHolder(#NonNull View itemView)
{
super(itemView);
first_name = itemView.findViewById(R.id.post_first_name);
last_name = itemView.findViewById(R.id.post_last_name);
post_date = itemView.findViewById(R.id.post_date_and_time);
post_body_text = itemView.findViewById(R.id.the_post);
}
}
----------------------------------------------
package com.example.updatedhapana1;
public class Posts
{
public String first_name, last_name, post_body_text, post_date;
//this is an empty contstructor- this is required//
public Posts ()
{
}
//this is an empty contstructor- this is required//
public Posts(String first_name, String last_name, String post_body_text, String post_date) {
this.first_name = first_name;
this.last_name = last_name;
this.post_body_text = post_body_text;
this.post_date = post_date;
}
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getPost_body_text() {
return post_body_text;
}
public void setPost_body_text(String post_body_text) {
this.post_body_text = post_body_text;
}
public String getPost_date() {
return post_date;
}
public void setPost_date(String post_date) {
this.post_date = post_date;
}
}
I haven't tested your code, but this is what I suspect. From your XML it seems like you have linear layout and recycler view in 2 separate components and your LinearLayout is match_parent.
So I am assuming it's taking the entire space.
I think it's your last FrameLayout where is height is match_parent and is overlapping everything.
If it's not this layout try to replace others layout by wrap_content or when your run your app, you have "layout inspector" in Android Studio and you can find your error.
Remove this from your Recyclerview: android:layout_marginTop="700dp"".
It has set the top margin 700dp which makes it go out of the screen.
Edit
I figured out my issue. My recycler view items were not displaying because of how my data was structured in firebase. Thank you everyone for your help.

RecyclerView item height and gravity not working

I have a problem with item height and gravity in a horizontal recyclerview as you can see in the picture: RecyclerView item height and gravity not working
How to set the item height to same height as recyclerciew and the gravity at the bottom of recyclerview ?
Thank you for your help.
My code for Activity_Drill_Graph.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context=".Drill_Graph_Activity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/toolbar_drill_graph"
layout="#layout/toolbar_drill_graph" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_5dp"
android:background="#color/grey"
android:gravity="bottom"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="#color/lightgrey"
android:orientation="vertical"
android:padding="#dimen/padding_5dp">
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_10"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_9"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_8"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_7"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_6"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_5"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_4"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_3"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_2"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_1"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textView0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/_0"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/textViewDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/date"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="18sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewDrillGraph"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_margin="#dimen/margin_5dp"
android:background="#color/white"
android:orientation="horizontal"
android:padding="#dimen/padding_5dp"
android:scrollbars="horizontal" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
item code: drill_graph_single_column.xml :
<?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="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="#color/lightgrey"
android:gravity="bottom"
android:orientation="vertical"
android:padding="#dimen/padding_1dp"
android:weightSum="110">
<Button
android:id="#+id/btnSkill"
style="#style/btnStyleScoreGrey"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:text="#string/skill"
android:textAllCaps="false"
android:textSize="16sp" />
<Button
android:id="#+id/btnDate"
style="#style/btnStyleDrillGraphGrey"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="#dimen/margin_1dp"
android:layout_weight="10"
android:text="#string/date"
android:textAllCaps="false"
android:textSize="12sp" />
</LinearLayout>
My code for RecyclerView Adapter:
package org.poolshot.poolshotacademy;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import java.util.List;
public class My_DrillGraph_RecyclerView_Adapter extends RecyclerView.Adapter<My_DrillGraph_RecyclerView_Adapter.MyHolder> {
SharedPreferences defaultPreferencesSettings;
private Context myRCAContext;
private List<String> myDrillGraphDates;
private List<Integer> myDrillGraphSkill;
// constructor
public My_DrillGraph_RecyclerView_Adapter(Context applicationContext, List<String> mDrillGraphDates, List<Integer> mDrillGraphSkill) {
this.myRCAContext = applicationContext;
this.myDrillGraphDates = mDrillGraphDates;
this.myDrillGraphSkill = mDrillGraphSkill;
}
#NonNull
#Override
public MyHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int position) {
View layout = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.drill_graph_single_column,null);
MyHolder myHolder = new MyHolder(layout);
return myHolder;
}
#Override
public void onBindViewHolder(#NonNull final MyHolder viewHolder, final int position) {
String skill = myDrillGraphSkill.get(position).toString();
// set color for buttons
viewHolder.btnDate.setBackground(myRCAContext.getResources().getDrawable(R.drawable.custom_btn_grey));
viewHolder.btnSkill.setTextColor(myRCAContext.getResources().getColor(R.color.white));
// set text for buttons
viewHolder.btnDate.setText(myDrillGraphDates.get(position));
viewHolder.btnSkill.setText(skill);
}
#Override
public int getItemCount() {
return myDrillGraphDates.size();
}
public static class MyHolder extends RecyclerView.ViewHolder {
Button btnDate;
Button btnSkill;
public MyHolder(View itemView) {
super(itemView);
btnDate = itemView.findViewById(R.id.btnDate);
btnSkill = itemView.findViewById(R.id.btnSkill);
}
}
}
This is my solution :
I changed the code of the class MyHolder as :
public static class MyHolder extends RecyclerView.ViewHolder {
Button btnDate;
Button btnSkill;
public MyHolder(View itemView) {
super(itemView);
btnDate = itemView.findViewById(R.id.btnDate);
btnSkill = itemView.findViewById(R.id.btnSkill);
LinearLayout.LayoutParams layoutParams =
new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.gravity = Gravity.BOTTOM;
itemView.setLayoutParams(layoutParams);
}
}

click related keyword like a search input

Hi sorry for my bad title (i really dont know how to phrase it better) but i have a cardview just like this cardview where the result/s returned are based on the user has input on the search bar.
All of the information returned are based on my database (DB Browser for SQLite). the cardview itself is not clickable but now I want the related keyword section to be clickable in a way where if a user click on one of the related keywords, it will open the cardview of that keyword like the same way when if the user search on it. (pardon me for my bad english!) As of now I only know that I have to add the clickable=true on the UI. However, logic-wise, I am not sure.
Below are my codes:
Cardview UI
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
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="wrap_content"
app:cardElevation="5dp"
android:layout_margin="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="8dp">
<LinearLayout
android:orientation="vertical"
android:layout_weight="9"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/keyword"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#000000"
android:textSize="15dp"
android:text="Baggage Management Interface Device (BMID) Testing
123"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/acronym"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|start"
android:textStyle="italic"
android:textColor="#a8000000"
android:text="GST"
android:textSize="13dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/description"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|start"
android:textColor="#a8000000"
android:text="If none are set then 'GST' is set to NULL"
android:textSize="13dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/relatedKeyword"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|start"
android:textColor="#a8000000"
android:text="Related Keyword:"
android:textSize="12sp"
android:textStyle="bold|italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/relatedKeyword1"
android:clickable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#a8000000"
android:text="Keyword 1"
android:textSize="12sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/relatedKeyword2"
android:clickable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#a8000000"
android:text="Keyword 2"
android:textSize="12sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/relatedKeyword3"
android:clickable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#a8000000"
android:text="Keyword 3"
android:textSize="12sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Search Adapter + SearchView Holder
package com.example.run_h.boav2.Adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.run_h.boav2.Model.Knowledge;
import com.example.run_h.boav2.R;
import java.util.List;
class SearchViewHolder extends RecyclerView.ViewHolder{
public TextView keyword, description, acronym, relatedkeyword1,
relatedkeyword2, relatedkeyword3;
public SearchViewHolder(#NonNull View itemView) {
super(itemView);
keyword = itemView.findViewById(R.id.keyword);
acronym = itemView.findViewById(R.id.acronym);
description = itemView.findViewById(R.id.description);
relatedkeyword1= itemView.findViewById(R.id.relatedKeyword1);
relatedkeyword2= itemView.findViewById(R.id.relatedKeyword2);
relatedkeyword3= itemView.findViewById(R.id.relatedKeyword3);
}
}
public class SearchAdapter extends RecyclerView.Adapter<SearchViewHolder>
{
private Context context;
private List<Knowledge> knowledge;
public SearchAdapter(Context context, List<Knowledge> knowledge) {
this.context = context;
this.knowledge = knowledge;
}
#NonNull
#Override
public SearchViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int
viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View itemView = inflater.inflate(R.layout.layout_item, parent,
false);
return new SearchViewHolder(itemView);
}
#Override
public void onBindViewHolder(#NonNull SearchViewHolder holder, int position)
{
holder.keyword.setText(knowledge.get(position).getKeyword());
holder.description.setText(knowledge.get(position).getDescription());
holder.acronym.setText(knowledge.get(position).getAcronym());
holder.relatedkeyword1.setText(knowledge.get(position).getRelatedkeyword1());
holder.relatedkeyword2.setText(knowledge.get(position).getRelatedkeyword2());
holder.relatedkeyword3.setText(knowledge.get(position).getRelatedkeyword3());
}
#Override
public int getItemCount() {
return knowledge.size();
}
}
Anyone knows how I can implement this? Much appreciated. Thanks!

How to pass data from bottom sheet to a fragment in android?

I am trying to pass values from a bottom sheet which contains some TextViews to a fragment.
My fragment contains an EditText field and a Floating action button.When the user clicks on the floating action button, the bottom sheet shows up which has a number of TextViews, when the user clicks on any of the textViews on the bottom sheet, the value or the string of that TextView should be displayed in the editText field of the fragment and the bottom sheet should be dismissed.
I have tried implementing the onClickListener inside the setOnShowListener method but it doesn't seem to work.
Here is my code:
Fragment_TextPropert1_EditText.xml
<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"
tools:context="com.example.sumitroy.TextProperty1_EditText"
>
<android.support.v7.widget.CardView 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="wrap_content"
android:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_below="#+id/view"
android:layout_marginTop="10dp"
app:cardUseCompatPadding="true"
android:id="#+id/view2">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:hint="Enter Your Comments Here.."
android:id="#+id/userText"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</android.support.v7.widget.CardView>
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:id="#+id/example_Ads"
android:background="#drawable/oval"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="20dp"
android:layout_marginRight="15dp"
android:src="#drawable/double_plus"
/>
</RelativeLayout>
TextProperty1_bottomsheet.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<android.support.v7.widget.CardView 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="wrap_content"
android:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="15dp"
app:cardUseCompatPadding="true"
android:id="#+id/view1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment1"
android:id="#+id/example_Ad1"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
android:layout_alignParentStart="true" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView 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="wrap_content"
android:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="10dp"
app:cardUseCompatPadding="true"
android:layout_below="#+id/view1"
android:id="#+id/view2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment 2"
android:id="#+id/example_Ad2"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView 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="wrap_content"
android:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="15dp"
app:cardUseCompatPadding="true"
android:id="#+id/view3"
android:layout_below="#+id/view2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment 3 "
android:id="#+id/example_Ad3"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView 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="wrap_content"
android:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="15dp"
app:cardUseCompatPadding="true"
android:id="#+id/view4"
android:layout_below="#+id/view3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment 4 "
android:id="#+id/example_Ad4"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView 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="wrap_content"
android:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="15dp"
app:cardUseCompatPadding="true"
android:id="#+id/view5"
android:layout_below="#+id/view4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment 5 "
android:id="#+id/example_Ad5"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
/>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
TextProperty1_EditText.java
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
/**
* A simple {#link Fragment} subclass.
*/
public class TextProperty1_EditText extends Fragment {
View bottomSheetView;
EditText editText1;
TextView t1;
BottomSheetDialog bottomSheetDialog;
BottomSheetBehavior bottomSheetBehavior;
ImageButton floatButton;
RelativeLayout backgroundLayout;
public TextProperty1_EditText() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View rootview= inflater.inflate(R.layout.fragment_text_property1__edit_text, container, false);
editText1=(EditText) rootview.findViewById(R.id.userText);
floatButton=(ImageButton)rootview.findViewById(R.id.example_Ads);
floatButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(v.getContext(),"Floating Button Works",Toast.LENGTH_SHORT).show();
bottomSheetView=getActivity().getLayoutInflater().inflate(R.layout.textproperty1_bottomsheet,null);
bottomSheetDialog=new BottomSheetDialog(rootview.getContext());
bottomSheetDialog.setContentView(bottomSheetView);
bottomSheetBehavior=BottomSheetBehavior.from((View) bottomSheetView.getParent());
bottomSheetDialog.show();
bottomSheetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
#Override
public void onShow(DialogInterface dialog) {
t1=(TextView)bottomSheetView.findViewById(R.id.example_Ad1);
t1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String take1=t1.getText().toString();
//Toast.makeText(bottomSheetView.getContext(),"Floating Button Works",Toast.LENGTH_SHORT).show();
editText1.setText(take1);
bottomSheetDialog.dismiss();
}
});
}
});
bottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
}
});
bottomSheetDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
#Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
//Toast.makeText(bottomSheetView.getContext(),"Floating Button Works",Toast.LENGTH_SHORT).show();
return false;
}
});
}
});
return rootview;
}
}
As a simple solution you may use LocalBroadcastManager.
public static final String SOME_INTENT_FILTER_NAME = "SOME_INTENT_FILTER_NAME";
In your fragment:
private BroadcastReceiver someBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
//TODO extract extras from intent
}
};
#Override
public void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(getContext()).registerReceiver(someBroadcastReceiver,
new IntentFilter(SOME_INTENT_FILTER_NAME));
}
#Override
public void onPause() {
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(someBroadcastReceiver);
super.onPause();
}
In your bottomsheet:
Intent someIntent = new Intent(SOME_INTENT_FILTER_NAME);
//TODO put extras to your intent
LocalBroadcastManager.getInstance(context).sendBroadcast(someIntent);

Categories

Resources