android - TextView doesn't displayed in RecyclerView - android

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.

Related

Unwanted spaces in recyclerview items in android

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.

View width for dynamically added view

I want to show a notification counter like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:padding="#dimen/_5sdp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:alpha=".5"
android:id="#+id/gvIcon"
android:src="#drawable/ic_person_reading"
android:scaleType="centerCrop"
android:layout_width="#dimen/_70sdp"
android:layout_height="#dimen/_70sdp" />
<LinearLayout
android:id="#+id/llTexts"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="#style/gridItemsText"
android:id="#+id/gvText"
android:text="Guten Morgen"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/partNoticeTooltip"
android:orientation="vertical"
android:background="#drawable/bg_tooltip_red"
android:layout_width="#dimen/tooltipWH"
android:layout_height="#dimen/tooltipWH">
<TextView
android:id="#+id/tvCounter"
android:text="4"
android:textColor="#color/white"
android:textSize="#dimen/h6"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Which has an output like this:
This is my expectation, but with dynamic way. So I wrote this in the setOnItemClickListener of my GridView:
View tooltip = context.getLayoutInflater().inflate(R.layout.part_tooltip, null);
TextView tvCounter = (TextView) tooltip.findViewById(R.id.tvCounter);
tvCounter.setText("" + counter);
LinearLayout llText = (LinearLayout) view.findViewById(R.id.llTexts);
llText.addView(tooltip);
the part_tooltip has exactly the same code but with another layout. And here is the output:
The red layout does not being displayed with full width. What am I missing?
You need to use a global layout listener and also the view tree observer:
ViewTreeObserver mVTO = parentLayoutOfTheViewAddedDynamically.getViewTreeObserver();
mVTO.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
if(viewAddedDynamically != null){
int viewWidth = viewAddedDynamically.getWidth();
// any operation based on viewWidth is to be done here
}
}
});

Shared Element Transition in GridView Weird behavior

I'm using Shared Elements Transition between an imageView in a gridView adapter and an imageView in a details activity , but when i click on an item in the GridView the imageView dosen't start to animate from the right position it always starts under the original place, and when i hit back the image animates to the right place correctly so the glitch happens only when entering the new activity.
https://youtu.be/cprBHWPVNbk (i've slowed down the animation so that the glitch is clear).
In the BrowseFragment's OnCreate :
gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ImageView gridPoster = (ImageView) view.findViewById(R.id.movie_poster);
gridPoster.setTransitionName("poster" + position);
listener.onItemSelected(movie,gridPoster);
Then the BrowseActivity's listener starts the detailsActivtiy :
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation
(this, posterView,posterView.getTransitionName());
Intent detailsIntent = new Intent(this, MovieDetalisActivity.class);
detailsIntent.putExtra(getString(R.string.movie_details_extra_key), movie);
detailsIntent.putExtra("transition",posterView.getTransitionName());
ActivityCompat.startActivity(this, detailsIntent, optionsCompat.toBundle());
Then in the DetailsFragment's OnCreate :
ImageView poster = (ImageView) rootView.findViewById(R.id.poster);
poster.setTransitionName(getActivity().getIntent().getStringExtra("transition"));
GridViewItem layout :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/gird_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#4e585c"
android:clipChildren="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="240dp"
android:id="#+id/movie_poster" />
<RelativeLayout
android:id="#+id/thumb_bottom_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:gravity="center_vertical">
<TextView
android:id="#+id/movie_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:fontFamily="sans-serif"
android:textColor="#aaa"
android:textSize="16sp"
/>
</RelativeLayout>
</LinearLayout>
Part of the DetailsView layout :
<android.support.v4.widget.NestedScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/scrollView"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:clipChildren="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.rashwan.popularmovies.MovieDetailsActivityFragment"
android:orientation="vertical"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="310dp"
android:orientation="horizontal"
android:padding="10dp"
android:baselineAligned="false"
android:clipChildren="false">
<FrameLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:clipChildren="false">
<ImageView
android:layout_width="wrap_content"
android:minWidth="220dp"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:id="#+id/poster" />
</FrameLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:padding="5dp"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ReleaseDate"
android:id="#+id/release_date"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:padding="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserRating"
android:id="#+id/user_rating"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:textAppearanceLarge"/>
</LinearLayout>
</LinearLayout>
And in my Theme i declared <item name="android:windowContentTransitions">true</item>i'm not using any custom animation although i tried some and i also tried to postpone the transition but nothing solved the problem.
I've found that the problem was that i'm using picasso library to load the images in the details fragment so i needed to use postponeEnterTransition(); in the details activity then in the details fragment i use getActivity().startPostponedEnterTransition(); to start the transition but only after the image is loaded using picasso.
Here's the code in the details fragment:
Picasso.with(getActivity()).load(posterUri).fit().into(poster, new Callback() {
#Override
public void onSuccess() {
poster.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
#Override
public boolean onPreDraw() {
if (isLollipop) {
poster.getViewTreeObserver().removeOnPreDrawListener(this);
getActivity().startPostponedEnterTransition();
}
return true;
}
});
}
Try putting your classes in manifest.AS

How to map a list of list to RecyclerView

I am trying to map a List<List<Object>> to a RecyclerView in Android, but the result is totally messed up.
For example, I have a list of list like this (just for explaining, not my real case):
List<List<String>> list = {{a, b, c}, {d, e}, {f, g, h, i}};
the Recyclerview should display like (first row contains three subrows, second has two and the last on has four):
|----a-----|
|----b-----|
|----c-----|
|=======|
|----d-----|
|----e-----|
|=======|
|----f-----|
|----g-----|
|----h-----|
|----i-----|
but the result is not exactly like the above order. some element is duplicated and some disappears. for example:
|----d-----|
|----e-----|
|----c-----|
|=======|
|----d-----|
|----e-----|
|=======|
|----f-----|
|----a-----|
Here is a piece of my code:
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
List<Event> list = eventList.get(position);
if (holder.rows < list.size()) {
holder.rowViewGroup.removeAllViews();
holder.rows = 0;
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
TextView startView = new TextView(context);
startView.setLayoutParams(layoutParams);
Event headEvent = list.get(0);
Calendar startCal = headEvent.getStartCal();
startView.setText(String.format("%tD", startCal));
holder.rowViewGroup.addView(startView);
for (final Event event : list) {
View element = LayoutInflater.from(context).inflate(R.layout.element, null);
//start time view
TextView startTimeView = (TextView)element.findViewById(R.id.eventStartTimeInElement);
Calendar startTimeCal = event.getStartCal();
startTimeView.setText(String.format("%tl:%tM %tp", startTimeCal, startTimeCal, startTimeCal));
//end date time view
TextView endView = (TextView)element.findViewById(R.id.eventEndTimeInElement);
Calendar endCal = event.getEndCal();
endView.setText(String.format("%tD %tl:%tM %tp", endCal, endCal, endCal, endCal));
//title view
TextView title = (TextView)element.findViewById(R.id.eventTitleInElement);
title.setText(event.getTitle());
//member name
Drawable divider = context.getResources().getDrawable(R.drawable.divider);
ImageView dividerView = new ImageView(context);
dividerView.setImageDrawable(divider);
holder.rowViewGroup.addView(dividerView);
holder.rowViewGroup.addView(element);
holder.rows++;
}
}
}
Here is my row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycleViewRow">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="2sp"
card_view:cardUseCompatPadding="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rowView"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/eventStartTimeInRow"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
and element.xml(which is contained by row.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/eventStartTimeInElement"
android:layout_weight="2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/eventEndTimeInElement"
android:gravity="end"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/eventTitleInElement"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2sp"
card_view:cardUseCompatPadding="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/memberNameInElement"
android:gravity="end"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
And I know this is not a really good idea to implement this, so could anybody please tell me a better way to implement this? Thanks...
I think your best bet is to flatten your list of lists into one list.
This is just for purposes of the ListView. Your adapter will act as though the lists have all been strung into one long list.
Start by creating a single-list index for all the items of your nested lists.
For example:
List<List<String>> listOfLists = ... // your original data
List<String> listForView = new ArrayList<String>();
for (List<String> innerList : listOfLists) {
for (String str : innerList) {
listForView.add(str);
}
listForView.add("---"); // e.g. marker value for divider
}
Now in your adapter's getItem() need only return listForView.get(position).
Anytime your nested list structure changes, you redo this flattening operation and call notifyDataSetChanged().
Things get a little trickier if — given the position — you have to figure out which list an item is in, but you could always index the inner lists in a similar fashion.

Android: Listview's row height changes when clicking on the checkbox it contains

I got an activity that contains a single listview.
This listview displays a relativeLayout with a bitmap and a checkbox and when no bitmap is available, a text is displayed.
My problem is with rows that contains no bitmap. When I click on the checkbox, the height of the row changes (increase when checkbox is checked, de crease when unchecked)
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/myListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#drawable/gradient_divider"
android:dividerHeight="1dp" />
</LinearLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:layout_toLeftOf="#+id/registrationCheckBox"
android:filter="true" >
</ImageView>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:paddingLeft="5dp"
android:layout_toLeftOf="#+id/registrationCheckBox" >
</TextView>
<CheckBox
android:id="#+id/registrationCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="false"
android:focusable="false"
android:paddingRight="5dp" >
</CheckBox>
</RelativeLayout>
My activity code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
hideActionBar();
// init the controls
initControls();
// populate the listView
this.adapter = new RegistrationAdapter(this, refreshContent());
this.listView.setAdapter(this.adapter);
this.listView.setItemsCanFocus(false);
this.listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
this.listView.setOnItemClickListener(
new ListView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ViewHolder viewHolder = (ViewHolder) view.getTag();
...
}
}
);
}
Any idea on how to prevent my row height to change when clicking on the checkbox ?
I think you are missing the important part of this code, and that is the Adapter code.
How are you handling switching between bitmap and text?
Perhaps set the ImageView to a fixed height (tall enough to fit in any actual image), or provide a dummy invisible image when there is no real image to show.

Categories

Resources