Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
Android setVisibility not working in PagerAdapter

I'm trying to hide and show part of my view in my PagerAdapter item but it doesn't do anything, not GONE, VISIBLE, or INVISIBLE.

public class FeedPagerAdapter extends PagerAdapter {
    private final String KEY_GLOBAL_PREFS = "global";

    @BindView(R.id.item) ImageView image;
    @BindView(R.id.progress_bar) ProgressBar progressBar;

    private final SlideActivity host;
    private List<Thing> items;

    private SharedPreferences sharedPreferences;

    private int postition;

    public FeedPagerAdapter(SlideActivity host, List<Thing> items){
        this.host = host;
        this.items = items;

        sharedPreferences = host.getSharedPreferences(KEY_GLOBAL_PREFS, Context.MODE_PRIVATE);
    }

    @Override
    public Object instantiateItem(final ViewGroup parent, int position) {
        final View view = LayoutInflater.from(host).inflate(R.layout.item_slide_reddit_post, parent, false);
        ButterKnife.bind(this, view);

        progressBar.setVisibility(View.GONE);

        return view;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}

Here's the item xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src:"..."/>
    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

And here is how the adapter is set up from the host activity:

adapter = new FeedPagerAdapter(SlideActivity.this, List<> of items);
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(position);
adapter.notifyDataSetChanged();

Any help would be awesome

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

It seems that using Butterknife or standard findViewById to setup ProgressBar item doesn't work to update the view, not sure why, maybe someone can explain. I solved by seeking out the actual item every time it's visibility needs to be changed in PagerAdapter like so:

@Override
    public Object instantiateItem(final ViewGroup parent, int position) {
        final View view = LayoutInflater.from(host).inflate(R.layout.item_slide_reddit_post, parent, false);
        ButterKnife.bind(this, view);

        view.findViewById(R.id.progress_bar).setVisibility(View.GONE);

        return view;
    }
over 4 years ago · Santiago Trujillo Denunciar

0

Look at that item.xml again, it looks for me ur image is match parent, and ur progress bar is wrap content. change image to wrap_contet and make sure progress bar appears on display!

over 4 years ago · Santiago Trujillo Denunciar

0

Add a notifyDataSetChanged() after the progressBar.setVisibility(View.GONE); maybe the line adapter.notifyDataSetChanged(); is happening before you set the progressBar visibility.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda