1

So basically I have maybe 50 records with images & text etc. There isn't too much data to be loaded in each list item but when I call setAdapter it is taking atleast 8 seconds to load only the first 3 items which are visible to the end user. I added logs and found that getView() in adapter is getting called twice. Is there any way I can reduce this time?

Before any one asks, I cannot use AsyncTask since I need to call setAdapter in main thread and the problem still occurs.

Would using a RecycleView make this a little more efficient? I understand that RecycleView is the next version of listView but I was not able to see any particular difference when it comes to setting the adapter.

Any help is appreciated! Thanks

UPDATE: This is my adapter code:

        @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder view;

        if (convertView == null) {
            view = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.fragment_test, null);

            view.inActiveView = convertView.findViewById(R.id.front);
            view.inActiveRewardTxt = (TextView) convertView.findViewById(R.id.status_lock_reward);
            view.inActiveTitleTxt = (TextView) convertView.findViewById(R.id.status_lock_title);

            view.completedView = convertView.findViewById(R.id.offerTitlePanel);

            view.activeView = convertView.findViewById(R.id.back);
            view.offerNumberTxt = (TextView) convertView.findViewById(R.id.offerNumberTxt);

            view.walletView = convertView.findViewById(R.id.offerWalletPanel);
            view.walletGiftView = (ImageView) convertView.findViewById(R.id.offerGiftImg);
            view.rewardTxt = (TextView) convertView.findViewById(R.id.offerWalletRibbonTxt);
            view.offerTitleTxt = (TextView) convertView.findViewById(R.id.offerTitleTxt);
            view.offerDescTxt = (TextView) convertView.findViewById(R.id.pagerDescTaskTxt);
            view.offerActionTxt = (TextView) convertView.findViewById(R.id.offerActionTxt);
            view.offerTimerTxt = (TextView) convertView.findViewById(R.id.offerTimerTxt);
            view.offerStatusBtn = (TextView) convertView.findViewById(R.id.offerStatusBtn);
            view.offerReportBtn = (TextView) convertView.findViewById(R.id.offerReportBtn);

            view.dataProgressBar = (ProgressBar) convertView.findViewById(R.id.data_loader);
            view.dataLoadedView = convertView.findViewById(R.id.loaded_view);
            view.calendarView = (CalendarView) convertView.findViewById(R.id.calendar_view);

            view.dataView = convertView.findViewById(R.id.dataView);
            view.dataInfoTxt = (TextView) convertView.findViewById(R.id.dataInfoTxt);
            view.dataEarnedTxt = (TextView) convertView.findViewById(R.id.dataEarnedTxt);
            view.dataProgress = (ProgressBar) convertView.findViewById(R.id.dataProgress);

            convertView.setTag(view);
        } else {
            view = (ViewHolder) convertView.getTag();
        }

  //display all the values here

return convertView;
Amir
  • 16,067
  • 10
  • 80
  • 119
  • are you using view holder pattern and lazy loading? – Raghunandan Feb 09 '16 at 15:09
  • I am using ViewHolder pattern in my custom adapter class. I use imageLoader library to load images to the listview –  Feb 09 '16 at 15:10
  • post your adapter code and read http://stackoverflow.com/questions/11945563/how-listviews-recycling-mechanism-works. Its better you switch to recyclerview – Raghunandan Feb 09 '16 at 15:11
  • Thanks will look into recycleView and see if it makes any significant difference –  Feb 09 '16 at 15:16
  • You have lot of views in your list and see if you can reduce that. see if you can use custom views and viewgroup as in some cases it gives good performance – Raghunandan Feb 09 '16 at 15:18
  • You mean like subclassing the listview item? –  Feb 09 '16 at 15:31
  • where are you decoding image data to `Bitmap`? – pskink Feb 09 '16 at 15:56

2 Answers2

0

Just judging by the code that you provided, it doesn't seem like it should take 8 seconds to load 3 views. Is it possible that you're doing any other heavy processing on the UI thread?

markreed49
  • 41
  • 7
0

So I used recyclerView to fix this issue. Thanks for all your help!