Alexey Markov Alexey Markov - 6 months ago 21
Android Question

android - TextView doesn't displayed in RecyclerView

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?


Answer

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.