El Peppe
El Peppe

Reputation: 30

ViewPager not responding quickly

While using a ViewPager i noticed that it wouldn't respond very quickly, meaning that it slows down when switchting through fragments, kind of in a laggy way. Does anyone know how this code could be causing the issue?

public class List_adapter : BaseAdapter<Element>
{
    public List<Element> _list; 
    FragmentOne _context;


    public List_adapter(FragmentOne context, List<Element> list) 
    {                                                 
    super(context, list);                     
        _list = list;
        _context = context;
    }
    @Override
    public int getCount() 
    {
        return _list.size();
    }
    @Override
    public Object getItem(int position) 
    {
        return _list.get(position);
    }
    @Override
    public long getItemId(int position) 
    {
        return getItem(position).hashCode();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        LayoutInflater inflater = (LayoutInflater)getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.row, parent, false); 
        Element item = getItem(position);
        TextView lbl = (TextView)view.findViewById(R.id.label);
        TextView prop = (TextView)view.findViewById(R.id.Prop);
        lbl.setText(item.getlabel()); 
        prop.setText(item.getprop()); 
        return view; 
    }


}

Upvotes: 1

Views: 81

Answers (1)

R. Zag&#243;rski
R. Zag&#243;rski

Reputation: 20258

  1. Use ViewHolder pattern for smooth list scrolling
  2. Implement Offscreen page limit for initialising a view before showing it inside ViewPager

Upvotes: 1

Related Questions