This question already has answers here:
FirestoreAdapter not working to populate a Recycler View
(2 answers)
Closed 3 years ago.
ONStart Code
#Override
public void onStart() {
super.onStart();
DatabaseReference cartlistref = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid()).child("Cart");
FirebaseRecyclerAdapter<Cart, CartViewHolder> adapter = new FirebaseRecyclerAdapter<Cart, CartViewHolder>(
Cart.class,
R.layout.cart_items,
CartViewHolder.class,
cartlistref
) {
#Override
protected void populateViewHolder(CartViewHolder holder, Cart cart, int i) {
holder.pname.setText(cart.getName());
holder.pprice.setText(cart.getPrice());
//holder.quantity.setNumber(cart.getQuantity());
}
};
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
}
CartViewHolder Code
public class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView pname,pprice ;
public ImageView pimage;
public ElegantNumberButton quantity;
ItemClickListener itemClickListener;
public CartViewHolder(#NonNull View itemView) {
super(itemView);
pname = itemView.findViewById(R.id.pname);
pprice = itemView.findViewById(R.id.pprice);
quantity = itemView.findViewById(R.id.qty);
pimage = itemView.findViewById(R.id.pimage);
}
#Override
public void onClick(View v) {
itemClickListener.onClick(v,getAdapterPosition(),false);
}
public void setItemClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
}
Cart items xml code
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:padding="16dp"
android:layout_height="160dp"
android:background="?attr/selectableItemBackground"
android:clickable="true">
<ImageView
android:id="#+id/pimage"
android:layout_width="151dp"
android:layout_height="match_parent"
app:srcCompat="#drawable/basket" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="150dp">
<TextView
android:id="#+id/pname"
android:layout_width="match_parent"
android:layout_height="57dp"
android:text="Product Name"
android:textSize="25sp"
android:textAlignment="center"
android:layout_gravity="center"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#android:color/black"
android:textStyle="normal|bold" />
<TextView
android:text="Product price"
android:textSize="18sp"
android:textAlignment="center"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/pprice"
android:layout_marginTop="4dp" />
<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
android:textSize="18sp"
android:layout_width="200dp"
android:layout_height="50dp"
android:id="#+id/qty"
android:visibility="visible"
android:layout_marginTop="10dp"
android:layout_gravity="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
Cart Fragment code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hackathon.shoppy.fragments.CartFragment">
<RelativeLayout
android:id="#+id/rill"
android:background="#color/colorPrimaryDark"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/totalamt"
android:textSize="20sp"
android:gravity="center"
android:textAlignment="center"
android:textColor="#android:color/white"
android:text="Total Amount = "
android:layout_width="match_parent"
android:layout_height="50dp"/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cartList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fancy:layout_constraintBottom_toTopOf="#+id/EditDetails"
fancy:layout_constraintEnd_toEndOf="parent"
fancy:layout_constraintStart_toStartOf="parent"
fancy:layout_constraintTop_toTopOf="parent"
android:layout_below="#+id/rill"
android:layout_above="#+id/checkout"/>
<mehdi.sakout.fancybuttons.FancyButton
android:id="#+id/checkout"
android:layout_width="280dp"
android:layout_height="66dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:textSize="20sp"
fancy:fb_defaultColor="#7ab800"
fancy:fb_radius="10dp"
fancy:fb_text="Proceed To Checkout"
fancy:fb_textColor="#FFFFFF" />
</RelativeLayout>
Firebase Database Structure
Here is the firebase database structure
I have tried the above code
I want to load cart items of a specific user from the firebase database
The view is loading but the recycler view items arent showing up
Also the app is not crashing and no errors in logcat
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cartList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fancy:layout_constraintBottom_toTopOf="#+id/EditDetails"
fancy:layout_constraintEnd_toEndOf="parent"
fancy:layout_constraintStart_toStartOf="parent"
fancy:layout_constraintTop_toTopOf="parent"
android:layout_below="#+id/rill"
android:layout_above="#+id/checkout"/>
here is your problem. You are telling recycler view to WRAP CONTENT. problem is, that in moment of creation, content is empty, so recycler view has height zero.
Try to use
android:layout_width="match_parent"
android:layout_height="match_parent"
and experiment with height. But width for sure better to be left as match_parent
I think its because of wrap content, try to fill color in recylerview with blue or something, if you are not able to see then change to match parent
Related
I want to show a popup menu for each item of a RecyclerView when a button is clicked.
My Adapter:
public class SearchResultRecyclerViewAdapter extends RecyclerView.Adapter<SearchResultRecyclerViewAdapter.ViewHolder> {
public SearchResultRecyclerViewAdapter(ArrayList<BookModel> bookModels, Context context) {
this.bookModels = bookModels;
this.context = context;
}
ArrayList<BookModel> bookModels;
Context context;
#NonNull
#NotNull
#Override
public ViewHolder onCreateViewHolder(#NonNull #NotNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_book,parent,false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
Log.d("aa", bookModels.get(position).getThumbnailLink());
Glide.with(context)
.asBitmap()
.load(bookModels.get(position).getThumbnailLink())
.into(holder.coverImage);
holder.name.setText(bookModels.get(position).getName());
holder.author.setText(bookModels.get(position).getAuthor());
holder.category.setText(bookModels.get(position).getCategories().toString());
holder.maturity.setText(bookModels.get(position).getMaturityRating());
holder.desc.setText(bookModels.get(position).getDesc());
holder.option.setOnClickListener(new View.OnClickListener() { ///////////// here
#Override
public void onClick(View v) {
//show popup
Log.d("ItemOption","Clicked");
}
});
if (position+1 == bookModels.size()){
holder.divider.setVisibility(View.GONE);
}
}
#Override
public int getItemCount() {
return bookModels.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
RoundedImageView coverImage;
TextView name;
TextView author;
TextView desc;
TextView category;
TextView maturity;
ImageView divider;
Button option;
RelativeLayout root;
public ViewHolder(#NonNull #NotNull View itemView) {
super(itemView);
coverImage = itemView.findViewById(R.id.cover_book_item_imageview);
name = itemView.findViewById(R.id.name_book_item_textview);
author = itemView.findViewById(R.id.author_book_item_textview);
desc = itemView.findViewById(R.id.desc_book_item_textview);
category = itemView.findViewById(R.id.category_book_item_textview);
maturity = itemView.findViewById(R.id.maturity_book_item_textview);
divider = itemView.findViewById(R.id.divider_book_item_imageview);
option = itemView.findViewById(R.id.option_book_item_button);
root = itemView.findViewById(R.id.root);
}
}
}
My item Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="#+id/cover_book_item_cardview"
android:layout_width="#dimen/_81sdp"
android:layout_height="#dimen/_124sdp"
android:layout_margin="#dimen/_15sdp"
app:cardCornerRadius="#dimen/_8sdp"
android:elevation="#dimen/_5sdp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/cover_book_item_imageview"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:src="#drawable/testcover"
android:scaleType="fitXY"
app:riv_corner_radius="#dimen/_5sdp"/>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/name_book_item_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
android:layout_marginTop="#dimen/_20sdp"
android:layout_alignStart="#id/cover_book_item_cardview"
android:layout_marginStart="#dimen/_90sdp"
android:fontFamily="#font/yanonekaffeesatz_medium"
android:layout_alignLeft="#id/cover_book_item_cardview"
android:layout_marginLeft="#dimen/_90sdp"
android:textSize="#dimen/_18sdp"
android:textColor="#color/light_black"
/>
<TextView
android:id="#+id/author_book_item_textview"
android:textSize="#dimen/_13sdp"
android:fontFamily="#font/yanonekaffeesatz_medium"
android:layout_marginTop="#dimen/_1sdp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/name_book_item_textview"
android:text="author"
android:layout_alignLeft="#id/cover_book_item_cardview"
android:layout_marginLeft="#dimen/_90sdp"
android:layout_alignStart="#id/cover_book_item_cardview"
android:layout_marginStart="#dimen/_90sdp"/>
<TextView
android:id="#+id/desc_book_item_textview"
android:layout_width="#dimen/_190sdp"
android:layout_height="#dimen/_40sdp"
android:layout_below="#id/name_book_item_textview"
android:width="#dimen/_60sdp"
android:layout_alignLeft="#id/cover_book_item_cardview"
android:layout_marginLeft="#dimen/_90sdp"
android:layout_alignStart="#id/cover_book_item_cardview"
android:layout_marginStart="#dimen/_90sdp"
android:layout_marginTop="#dimen/_30sdp"
android:textColor="#color/light_black"
android:text="desc"
android:fontFamily="#font/yanonekaffeesatz_medium"/>
<LinearLayout
android:id="#+id/holder_book_item_linearlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/name_book_item_textview"
android:layout_alignLeft="#id/cover_book_item_cardview"
android:layout_marginLeft="#dimen/_90sdp"
android:layout_alignStart="#id/cover_book_item_cardview"
android:layout_marginStart="#dimen/_90sdp">
<TextView
android:id="#+id/category_book_item_textview"
android:textColor="#color/white"
android:fontFamily="#font/yanonekaffeesatz_medium"
android:background="#drawable/rounded_rectangle_90"
android:backgroundTint="#color/yellow"
android:padding="#dimen/_3sdp"
android:layout_marginTop="#dimen/_72sdp"
android:text="category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/maturity_book_item_textview"
android:textColor="#color/white"
android:fontFamily="#font/yanonekaffeesatz_medium"
android:background="#drawable/rounded_rectangle_90"
android:backgroundTint="#color/light_black"
android:padding="#dimen/_3sdp"
android:layout_marginTop="#dimen/_72sdp"
android:text="maturity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"/>
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/option_book_item_button"
android:layout_width="#dimen/_20sdp"
android:layout_height="#dimen/_20sdp"
android:background="#drawable/ic_more"
android:backgroundTint="#color/light_black"
android:layout_alignLeft="#id/cover_book_item_cardview"
android:layout_marginLeft="#dimen/_260sdp"
android:layout_alignStart="#id/cover_book_item_cardview"
android:layout_marginStart="#dimen/_260sdp"
android:layout_marginTop="#dimen/_23sdp"/>
<ImageView
android:id="#+id/divider_book_item_imageview"
android:layout_width="#dimen/_200sdp"
android:layout_height="1dp"
android:background="#DFDFDF"
android:layout_below="#id/holder_book_item_linearlayout"
android:layout_marginTop="#dimen/_15sdp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Initializing RecyclerView:
recyclerView = findViewById(R.id.search_result_recyclerview);
recyclerView.scheduleLayoutAnimation();
recyclerView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("CheckRecyclerView","clicked");
}
});
searchResultRecyclerViewAdapter = new SearchResultRecyclerViewAdapter(bookModels,SearchActivity.this);
recyclerView.setAdapter(searchResultRecyclerViewAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(SearchActivity.this));
}
XML Layout of Activity:
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerlayout"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:layout_width="match_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:gravity="center"
android:animateLayoutChanges="true"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--
Views
-->
<androidx.recyclerview.widget.RecyclerView
android:layout_centerHorizontal="true"
android:layout_below="#id/appbar_cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/search_result_recyclerview"
android:layoutAnimation="#anim/search_result_recyclerview_anim"
android:visibility="gone"/> <!-- will become visible later-->
<!--
Views
-->
</RelativeLayout>
<com.google.android.material.navigation.NavigationView
app:itemTextColor="#color/white"
app:itemIconTint="#color/white"
android:background="#color/black"
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header"
app:menu="#menu/menu_main" />
</androidx.drawerlayout.widget.DrawerLayout>
when the item's view is clicked nothing happens. I've done the same exact thing before with no problem I don't know what I'm missing here.
EDIT:
as #anemomylos mentioned this might be a click issue. in this layout there is a lot of Views that will be Gone in order to RecyclerView shows up. RecyclerViews don't register any clicks themselves so I'm not sure if it's being blocked by another view or not, is there any way to know what is blocking the click? I don't have any android:clickable="true" and I made sure that all Views before RecyclerView are Gone and not Invisible
I am using Horizontal Recycler View :
My Layout file contains recyclerview as below :
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_Styles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white" />
My custom/singleview/raw file to be bind in RecyclerView is as below :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:maxLines="2"
android:ellipsize="end"
android:layout_centerHorizontal="true"
android:id="#+id/txt_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/dimen_10"
android:text="Style"
android:textColor="#color/black" />
<View
android:layout_centerHorizontal="true"
android:id="#+id/viewStyle"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_2"
android:layout_below="#+id/txt_style"
android:background="#color/colorAppDefault" />
<!--#455A90-->
My viewStyle is display when I am giving its width to Fix. But, Its look improper.
What might be the issue ?
I am doing as below in My Adapter.
public RecyclerViewHolders(View itemView) {
super(itemView);
txt_style = (TextView) itemView.findViewById(R.id.txt_style);
viewStyle = itemView.findViewById(R.id.viewStyle);
}
public void setData(DrinkStyleModel modelBeerStyle, final int position) {
final DrinkStyleModel modelFinal = modelBeerStyle;
if (modelFinal.is_check()) {
txt_style.setTextColor(context.getResources().getColor(R.color.black));
viewStyle.setVisibility(View.VISIBLE);
} else {
txt_style.setTextColor(context.getResources().getColor(R.color.gray));
viewStyle.setVisibility(View.GONE);
}
}
How can I delete the space when I hide a CardView? I doing an app with android and Firebase and I show the information from firebase in cardviews, but when the info isn't correct the cardview must disappear. The point is that the cardview disappear, but still uses a space in the layout, I've tried the answers in
setVisibility(GONE) view becomes invisible but still occupies space But it doesn't work for me.
#Override
protected void onStart() {
super.onStart();
firebaseAuth.addAuthStateListener(firebaseAuthListener);
final FirebaseRecyclerAdapter<CursosDB, MainActivity.CursosPViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<CursosDB, MainActivity.CursosPViewHolder>(
CursosDB.class,
R.layout.design_row_cursos,
MainActivity.CursosPViewHolder.class,
myRef)
{
#Override
protected void populateViewHolder(MainActivity.CursosPViewHolder viewHolder, final CursosDB Cmodel, int position)
{
String estado = Cmodel.getSTATUS().toString();
if (estado.equals("OK")){
viewHolder.setPhotoURL(getApplicationContext(), Cmodel.getURI());
viewHolder.setTitle(Cmodel.getTITLE());
viewHolder.setCiudad(Cmodel.getPLACE());
viewHolder.setLevel(Cmodel.getLEVEL());
viewHolder.setDur(Cmodel.getDURACION());
viewHolder.setPrice(Cmodel.getCOSTO());
}else{
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) viewHolder.mView.getLayoutParams();
layoutParams.setMargins(0,0,0,0);
viewHolder.mView.setLayoutParams(layoutParams);
viewHolder.mView.setVisibility(View.INVISIBLE);
viewHolder.mView.setVisibility(View.GONE);
//viewHolder.mView.setVisibility(View.GONE);
//Toast.makeText(getApplicationContext(), "Ningún curso aprobado aún", Toast.LENGTH_SHORT).show();
}
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Toast.makeText(getApplicationContext(), Cmodel.getUSERID(), Toast.LENGTH_LONG).show();
//Toast.makeText(getApplicationContext(), Cmodel.getTITLE(), Toast.LENGTH_SHORT).show();
//Toast.makeText(UsersList.this, user_key, Toast.LENGTH_LONG).show();
}
});
}
};
mCourses.setAdapter(firebaseRecyclerAdapter);
}
This is my layout:
<?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:id="#+id/cardview_cursos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:onClick="positionAction"
android:padding="4dp"
android:paddingBottom="4dp"
android:paddingEnd="4dp"
android:paddingStart="4dp"
android:paddingTop="4dp"
app:cardElevation="4dp">
<LinearLayout android:id="#+id/layout_to_hide"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/Cimg"
android:layout_width="match_parent"
android:layout_height="165dp"
android:scaleType="center"
app:srcCompat="#drawable/knowit_logo" />
<TextView
android:id="#+id/Ctitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/Cimg"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:paddingTop="8dp"
android:text="Titulo"
android:textStyle="bold" />
<TextView
android:id="#+id/Clugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/Ctitle"
android:layout_alignStart="#+id/Ctitle"
android:layout_below="#+id/Ctitle"
android:layout_marginTop="10dp"
android:text="Lugar" />
<TextView
android:id="#+id/textView29"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/Clugar"
android:layout_alignStart="#+id/Clugar"
android:layout_below="#+id/Clugar"
android:layout_marginTop="10dp"
android:text="$" />
<TextView
android:id="#+id/Cprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView29"
android:layout_marginBottom="4dp"
android:layout_toEndOf="#+id/textView29"
android:layout_toRightOf="#+id/textView29"
android:paddingLeft="5dp"
android:text="0.0" />
<TextView
android:id="#+id/Cdur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/Clugar"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="126dp"
android:layout_marginRight="126dp"
android:text="Duración" />
<TextView
android:id="#+id/Cnivel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/Cprice"
android:layout_alignLeft="#+id/Cdur"
android:layout_alignStart="#+id/Cdur"
android:layout_marginBottom="0dp"
android:text="Nivel" />
</RelativeLayout>
</LinearLayout> </android.support.v7.widget.CardView>
This is the mView:
public static class CursosPViewHolder extends RecyclerView.ViewHolder {
View mView;
public CursosPViewHolder(final View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String title){
TextView post_title = (TextView)mView.findViewById(R.id.Ctitle);
post_title.setText(title);
}
public void setCiudad (String ciudad){
TextView post_city = (TextView)mView.findViewById(R.id.Clugar);
post_city.setText(ciudad);
}
public void setPhotoURL(Context ctx, String pgotouserurl) {
ImageView post_image =(ImageView)mView.findViewById(R.id.Cimg);
Picasso.with(ctx).load(pgotouserurl).into(post_image);
} }
I hope you can help me.
First the XML code you've posted ils wrong closed,(must finish with a CardView tag)
On addition be sure you're pointing the CardView layout with mView field ans Only use GONE or INVISIBLE,
INVISIBLE change your Panel ( Root view ) structure but GONE don't
I have spaces on recyclerview of my app and i don't know why are there because i have done the samething using the recyclerview and this adapter and did not added unwanted space...but now it is.
Help please
Here is my home layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="ideias.prime.mungano.Home"
tools:showIn="#layout/activity_home">
<android.support.v7.widget.RecyclerView
android:id="#+id/clients_rv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
And here is the recyclerview Item model
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cl_CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
card_view:cardBackgroundColor="#color/colorAccent"
card_view:cardCornerRadius="12dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="6dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:id="#+id/cl_name"
android:layout_width="69dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:ellipsize="end"
android:fitsSystemWindows="true"
android:padding="4dp"
android:singleLine="true"
android:text="#string/cl_name"
android:textColor="#color/colorPrimaryText"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:id="#+id/nome_do_cliente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/cl_name"
android:ellipsize="end"
android:fitsSystemWindows="true"
android:padding="4dp"
android:singleLine="true"
android:text="#string/programmer"
android:textColor="#color/colorPrimaryText"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:id="#+id/cl_work"
android:layout_width="82dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/cl_name"
android:ellipsize="end"
android:fitsSystemWindows="true"
android:padding="4dp"
android:singleLine="true"
android:text="#string/cl_work"
android:textAlignment="center"
android:textColor="#color/colorPrimaryText"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:id="#+id/trabalho_do_cliente"
android:layout_width="99dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cl_work"
android:layout_toEndOf="#+id/cl_work"
android:ellipsize="end"
android:fitsSystemWindows="true"
android:singleLine="true"
android:text="#string/primeIdeas"
android:textColor="#color/colorPrimaryText"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:id="#+id/cl_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/cl_work"
android:fitsSystemWindows="true"
android:padding="4dp"
android:text="#string/cl_phone"
android:textColor="#color/colorPrimaryText"
android:textSize="15sp" />
<TextView
android:id="#+id/telefone_do_cliente"
android:layout_width="99dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cl_phone"
android:layout_toEndOf="#+id/cl_work"
android:ellipsize="end"
android:fitsSystemWindows="true"
android:singleLine="true"
android:text="#string/primeIdeas"
android:textColor="#color/colorPrimaryText"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:id="#+id/cl_LP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/trabalho_do_cliente"
android:layout_alignParentEnd="true"
android:ellipsize="end"
android:ems="10"
android:fitsSystemWindows="true"
android:padding="4dp"
android:singleLine="true"
android:text="#string/cl_LP"
android:textColor="#color/colorPrimaryText"
android:textSize="15sp" />
<TextView
android:id="#+id/cl_LP_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/telefone_do_cliente"
android:layout_alignParentEnd="true"
android:ellipsize="end"
android:ems="10"
android:fitsSystemWindows="true"
android:padding="4dp"
android:singleLine="true"
android:text="#string/cl_Lp_info"
android:textColor="#color/colorPrimaryText"
android:textSize="15sp" />
<TextView
android:id="#+id/cl_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="53dp"
android:layout_toEndOf="#+id/cl_phone"
android:ellipsize="end"
android:ems="10"
android:fitsSystemWindows="true"
android:padding="4dp"
android:singleLine="true"
android:text="#string/Id"
android:textColor="#color/colorPrimaryText"
android:textSize="15sp"
android:visibility="gone" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
And here is the Adapter
public class Rv_adapter extends RecyclerView.Adapter<Rv_adapter.Holder> {
private Context context;
private List<Model> list = new ArrayList<>();
private Face f;
public Rv_adapter(Context c) {
context = c;
}
public Rv_adapter(Context c, List<Model> l) {
this.context = c;
this.list = l;
}
public void Listenner(Face interfaCe) {
this.f = interfaCe;
}
#Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context.getApplicationContext()).inflate(R.layout.rv_model, parent, false);
return new Holder(v);
}
#Override
public void onBindViewHolder(Holder holder, int position) {
holder.Id.setText(list.get(position).getId());
holder.Name.setText(list.get(position).getName());
holder.Lp.setText(list.get(position).getLp());
holder.Phone.setText(list.get(position).getPhone());
holder.Work.setText(list.get(position).getWork());
}
#Override
public int getItemCount() {
return list.size();
}
class Holder extends RecyclerView.ViewHolder {
private CardView c;
private TextView Id, Name, Work, Phone, Lp;
public Holder(View i) {
super(i);
c = (CardView) i.findViewById(R.id.cl_CardView);
Id = (TextView) i.findViewById(R.id.cl_id);
Name = (TextView) i.findViewById(R.id.nome_do_cliente);
Work = (TextView) i.findViewById(R.id.trabalho_do_cliente);
Phone = (TextView) i.findViewById(R.id.telefone_do_cliente);
Lp = (TextView) i.findViewById(R.id.cl_LP_info);
}
} // end
public interface Face {
void Clicked(View v, int position, String cl_id);
}
}
Here goes the screenshots of the unwanted spaces on the recyclerview
change your recyclerview Height from android:layout_height="match_parent" to
android:layout_height="wrap_content".
and why you are giving scrolling behavior to Your relative layout ??? RecyclerView already hve that!
There is no problem with your recyclerview, you should make changes in R.layout.rv_model file. You have set android:fitsSystemWindows="true" property to<TextView>.
Most of the time, your app won’t need to draw under the status bar or the navigation bar, but if you do: you need to make sure interactive elements (like buttons) aren’t hidden underneath them. That’s what the default behavior of the android:fitsSystemWindows=“true” attribute gives you: it sets the padding of the View to ensure the contents don’t overlay the system windows.
A few things to keep in mind:
fitsSystemWindows is applied depth first — ordering matters: it’s the first View that consumes the insets that makes a difference
Insets are always relative to the full window — insets may be applied even before layout happens, so don’t assume the default behavior knows anything about the position of a View when applying its padding
Any other padding you’ve set is overwritten — you’ll note that paddingLeft/paddingTop/etc is ineffective if you are using android:fitsSystemWindows=”true” on the same View
And, in many cases, such as a full screen video playback, that’s enough. You’d have your full bleed view with no attribute and another full screen ViewGroup with android:fitsSystemWindows=”true” for your controls that you want inset.
Or maybe you want your RecyclerView to scroll underneath a transparent navigation bar — by using android:fitsSystemWindows=”true” in conjunction with android:clipToPadding=”false”, your scrolling content will be behind the controls but, when scrolled to the bottom, the last item will still be padded to be above the navigation bar (rather than hidden underneath!).
Check if you want more information about android:fitsSystemWindows
Your item layout is filling one length of your screen each.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" <!-- Here needs to be wrap_content -->
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cl_CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
And remove android:fitsSystemWindows="true" from the TextViews because they don't need to fit the system window.
I've got an app which got some data (titles of youtube videos) and displayed them in the TextViews which in the items in RecyclerView. But some of TextViews are not displayed, but data is loaded correctly.
On my phone don't displayed only few elements of list, on my old tabled - almost all elements are not displayed.
I do some experiments and learned that strings longer then some value are not displayed.
List item
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
android:padding="3dp"
android:background="#color/colorAccent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/galley_photo_item_image"
android:layout_width="120dp"
android:layout_height="120dp"/>
<CheckBox
android:id="#+id/galley_photo_item_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"
android:visibility="invisible"/>
</FrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="WTF"
android:minLines="3"
android:maxLines="3"
android:background="#color/colorPrimary"
android:id="#+id/image_name_text"/>
</LinearLayout>
My Adapter
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int i)
{
View convertView = inflater.inflate(R.layout.gallery_photo_item,parent,false);
ViewHolder view_holder = new ViewHolder(convertView);
//view_holder.Position = i;
//Event handling
view_holder.CheckBox.setOnClickListener(this);
view_holder.View.setOnClickListener(this);
convertView.setTag(view_holder);
//checkBox.setTag(position);
return view_holder;
}
#Override
public void onBindViewHolder(ViewHolder view_holder, int position)
{
//Toggle checkbox on DELETE MODE
if(is_checking) {
view_holder.CheckBox.setVisibility(View.VISIBLE);
view_holder.CheckBox.setChecked(checked[position]);
}
else
view_holder.CheckBox.setVisibility(View.INVISIBLE);
//view.setTag(position);
view_holder.CheckBox.setTag(position);
view_holder.Position=position;
//Display image
//String uri = Uri.fromFile(thumbs[position]).toString();
String uri = thumbs_fnames[position];
Glide.with(context)
.load(uri)
.centerCrop()
.into(view_holder.ImageView);
//Добавляем подписи (если есть)
if((thumbs_descriptions!=null))//&&(thumbs_descriptions.length==thumbs_fnames.length))
{
String text = thumbs_descriptions[position];
Log.d("ImageListAdapter",position +": "+text+"|");
view_holder.Description.setText(text);
}
else
Log.d("ImageListAdapter",position + ": nothing");
if(position== markred_id)
view_holder.View.setBackgroundResource(R.color.colorPrimary);
else
view_holder.View.setBackgroundResource(R.color.transparent);
}
And the last strange thing. When I set the text manually:
text = "Some long-long text bla-bla-bla ... ... ... ...;
it works correctly.
What the strange problem?
I did it. The problew was that FrameLayout has width and height mathc_parent instend wrap_content.
Correct XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
android:padding="3dp">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/galley_photo_item_image"
android:layout_width="120dp"
android:layout_height="120dp"/>
<CheckBox
android:id="#+id/galley_photo_item_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"
android:visibility="invisible"/>
</FrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minLines="3"
android:maxLines="3"
android:id="#+id/image_name_text"/>
Diff: https://www.diffchecker.com/qe8pcozv
You can also see difference in TextView height, but it doesn't metter, It works in both situations.