Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:45:17+00:00 2026-06-17T22:45:17+00:00

I have created a dynamic listview with lazy loading. I am trying to show

  • 0

I have created a dynamic listview with lazy loading. I am trying to show a footer to the listview, so that when the user scrolls to the bottom of the listview, it will show “loading more items” (as a footer)and it will load more item.I have implemented lazy loading. I have set the the footer, but it is not getting displayed on the listview. Please help me out.

Tabfragment class containing listview:

package com.example.abe;

import java.util.ArrayList;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class Tab1Fragment extends ListFragment {
    ListView lv;
    Activity act = this.getActivity();
    Context ct = this.getActivity();
    XMLGettersSetters data;
    boolean loadingMore = false;
    String abc[] = new String[50];
    static int count = 0;
    final int itemsPerPage = 10;
    static ArrayList<String> myListItems = new ArrayList<String>();
    ArrayList<String> myListItems2;
    ArrayAdapter<String> adapter;
    ArrayAdapter<String> adapter1;

    static int size = 0;
    int position = 0;
    int top = 0;
    static String android_array1[];
    ArrayList<String> myListItems3;

    TabsFragmentActivity t = new TabsFragmentActivity();
    String parsed[] = new String[MainActivity.Sarray1.length];

    @SuppressWarnings("unused")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        adapter = new ArrayAdapter<String>(getActivity().getBaseContext(),
                android.R.layout.simple_list_item_1, t.myarray);
        ;
        View root = inflater.inflate(R.layout.tab_frag1_layout, container,
                false);
        lv = (ListView) root.findViewById(android.R.id.list);
        lv.setAdapter(adapter);
        getActivity().setTitle("ABE ST count: " + t.stcount + " items");
        parsed = MainActivity.Sarray1;
        for (int j = 0; j < parsed.length; j++) {
            System.out.println("sax" + parsed[j].toString());
        }

        return root;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        View footerView = ((LayoutInflater) this.getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
                R.layout.listfooter, null, false);
        lv.addFooterView(footerView);

        getListView().setOnScrollListener(new OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {
                System.out.println(abc.length);
                System.out.println(count);
                System.out.println("First" + firstVisibleItem);
                System.out.println("Vis" + visibleItemCount);
                position = firstVisibleItem;
                View v = lv.getChildAt(0);
                top = (v == null) ? 0 : v.getTop();
                int lastInScreen = firstVisibleItem + visibleItemCount;
                System.out.println("Last" + lastInScreen);
                System.out.println("Total" + totalItemCount);
                if ((lastInScreen == totalItemCount) && !(loadingMore)) {
                    if (count < size) {
                        try {
                            Thread thread = new Thread(null, loadMoreListItems);
                            thread.start();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }

                    else if (count != 0) {
                        Toast.makeText(getActivity().getApplicationContext(),
                                "Complete Data", Toast.LENGTH_LONG).show();
                        int lvcnt = lv.getCount();
                        System.out.println("Adapter Count " + " " + lvcnt);
                        System.out.println("Abe adapter count" + " "
                                + adapter.getCount());
                    }
                }
            }
        });
        if (t.check1 == 0) {
            try {
                Thread thread = new Thread(null, loadMoreListItems);
                thread.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private Runnable loadMoreListItems = new Runnable() {
        @Override
        public void run() {
            loadingMore = true;
            t.myarray1 = new ArrayList<String>();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            size = parsed.length;
            for (int i = 0; i < itemsPerPage; i++) {
                if (count < size) {
                    t.myarray1.add(parsed[count].toString());

                    count = count + 1;
                    System.out.println("Count in run " + " " + count);
                } else {
                    break;
                }
            }
            Log.i("a", "b");
            try {
                getActivity().runOnUiThread(returnRes);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Log.i("a", "b");
        }
    };
    private Runnable returnRes = new Runnable() {
        @Override
        public void run() {
            if (t.myarray1 != null && t.myarray1.size() > 0) {
                for (int j = 0; j < t.myarray1.size(); j++) {
                    adapter.add(t.myarray1.get(j));

                    // adapter1.add(myListItems3.get(j));

                }
            }
            // setListAdapter(adapter);
            Log.i("a", "b");
            adapter.notifyDataSetChanged();
            // lv.setSelection(position);
            lv.setSelectionFromTop(position, top);
            Log.i("a", "b");
            getActivity().setTitle(
                    "ABE ST count: " + String.valueOf(adapter.getCount())
                            + " items");
            t.stcount = adapter.getCount();
            loadingMore = false;
            t.check1 = 1;

        }
    };
}

Listfooter xml(Used int tabfragment class): XML for the footer:

<?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"
android:paddingTop="7dip"
android:paddingBottom="7dip"
android:orientation="horizontal"
android:gravity="center">

<LinearLayout 
    android:id="@+id/footer_layout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center"
    android:layout_gravity="center">

<TextView
    android:id="@+id/footer_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="5dip"
    android:text="Loading"
    android:textSize="14sp"
    android:textStyle="bold" />

</LinearLayout>
</LinearLayout> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:45:18+00:00Added an answer on June 17, 2026 at 10:45 pm

    Actually, you have to add FooterView to List before setting Adapter.. Like Below..

    View root = inflater.inflate(R.layout.tab_frag1_layout, container,
                    false);
    lv = (ListView) root.findViewById(android.R.id.list);
    View footerView = ((LayoutInflater) this.getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
                    R.layout.listfooter, null, false);
    lv.addFooterView(footerView);
    lv.setAdapter(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a dynamic list picker script using Jquery 1.3 and PHP that
I have a listview that loads dynamic controls from xml/xslt <asp:ListView ID=DynamicFields runat=server DataSourceID=CustomFields
I have created an android app that works as designed. However, onCreate() uses dynamic(not
I have created dynamic web project. In that I have written one Java class
I have created a dynamic listview which contains a CheckBox.what I want is at
If you have every created a dynamic page, you may notice that if you
I have created and Excel 2007 based dynamic charting application that that charts various
I have a ListView that is filled with a dynamic set of data each
I have created a dynamic form using jQuery that has two sections, once the
I have created a dynamic TableLayout. In rows of table I show data parsed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.