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 6799387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:50:33+00:00 2026-05-26T18:50:33+00:00

I have a list view in which I am loading 10 items. I want

  • 0

I have a list view in which I am loading 10 items.

I want only 3 items visible when I scroll it.

I don’t want to do it by adjusting the list height, and I want to show only 3 items even when I scroll little (means no item should appear partially).

How to achieve this…?

Thanks in advance..!

  • 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-05-26T18:50:34+00:00Added an answer on May 26, 2026 at 6:50 pm

    I will post a code which I have used to populated 10 records each on scroll event.

      /**
         * Called when the activity is first created.
         * 
         * @param savedInstanceState
         *            the saved instance state
         */
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
                 setContentView(R.layout.view_checkin_checkout_history);
    
                 Thread thread = new Thread() {
    
                public void run() {
    
                           synchronized (this) {
                        fetchHistory(0);
    
                        handler.post(new Runnable() {
                            public void run() {
                                pd.dismiss();
    
                                displayUI();
                            };
                        });
                    }
                }
            };
    
            thread.start();
             }
    
           /**
         * Display the check in check out history list.
         */
        private void displayUI() {
            if ((checkInCheckOutHistoryList != null)
                    && (checkInCheckOutHistoryList.size() > 0)) {
                historyArrayList = new ArrayList<HashMap<String, String>>();
    
                histroyListAdapter = new SimpleAdapter(
                        ViewCheckInCheckOutHistory.this, historyArrayList,
                        R.layout.multi_colummn_list_text_style_small, new String[] {
                                "assetTag", "gif" , "action", "actionTime"},
                        new int[] { R.id.list_content_column1,
                                R.id.list_content_imagecolumn,
                                R.id.list_content_column3,
                                R.id.list_content_column4});
    
                // To add more items to list view on scroll event.
                historyListView.setOnScrollListener(new OnScrollListener() {
    
                    @Override
                    public void onScrollStateChanged(AbsListView view,
                            int scrollState) {
                    }
    
                    @Override
                    public void onScroll(AbsListView view, int firstVisibleItem,
                            int visibleItemCount, int totalItemCount) {
    
                        int lastInScreen = firstVisibleItem + visibleItemCount;
    
                        if ((lastInScreen == totalItemCount) && !(loadingMore) && (lastInScreen < totalHistoryItemCount)) {
    
                            if (!firstInstance) {
                                openSlider();                           
                            }                           
    
                            fetchHistory(lastInScreen);     
    
                            Thread thread = new Thread(null, loadMoreListItems);
                            thread.start();
                        }
                    }
                });
                         }
                      }
    
    // Runnable to load the items
    
        private Runnable loadMoreListItems = new Runnable() {
    
            @Override
            synchronized public void run() {
                // Set flag so we cant load new items 2 at the same time
                loadingMore = true;
    
                HashMap<String, String> historyObjectMap;
    
                for (CheckInCheckOutHistory checkOutHistoryObj : checkInCheckOutHistoryList) {
                    historyObjectMap = new HashMap<String, String>();
                    historyObjectMap.put("assetTag",
                            checkOutHistoryObj.getAssetTag());
                    historyObjectMap.put("action", checkOutHistoryObj.getAction());
                    historyObjectMap.put("actionTime",
                            checkOutHistoryObj.getActionDate());
    
                    if (checkOutHistoryObj.getAction().equals("Checked out")) {
                        historyObjectMap.put("gif", R.drawable.radio_button_yellow
                                + "");
                    } else {
                        historyObjectMap.put("gif", R.drawable.radio_button_green
                                + "");
                    }
    
                    historyArrayList.add(historyObjectMap);
                }
    
                runOnUiThread(returnRes);
            }
        };
    
        // Since we cant update our UI from a thread this Runnable takes care of
        // that!
        private Runnable returnRes = new Runnable() {
            @Override
            public void run() {
    
                // Add the new items to the adapter
                if (historyArrayList != null && historyArrayList.size() > 0) {
                    histroyListAdapter.notifyDataSetChanged();
                }
    
                if (firstInstance) {
                    historyListView.setAdapter(histroyListAdapter);
                    firstInstance = false;
                }
    
                historyListLayout.setVisibility(View.VISIBLE);
    
                // Done loading more.
                loadingMore = false;
    
                if ((slidingDrawer.isOpened()) && (!loadingMore)) {
    
                    handler.postDelayed(new Runnable() {
    
                        @Override
                        public void run() {
                            slidingDrawer.close();
                            slidingDrawer.setVisibility(View.GONE);
                        }
                    }, 1000);
    
                }
            }
        };
    

    fetchHistory(int count) is the method I have used to set the values for totalHistoryItemCount & checkInCheckOutHistoryList.

    Hope this would help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list view control which at the moment only allows one item
I have a list view in which I am loading my own layout. I
I have a list view in which I can insert items(the items are inserted
I have a UINavigationController in which I am loading different view controllers. I want
I currently have a list view which has several rows of data and I
I have recently built a list view which shows a number of products taken
I want to create a list view which contain TextViews that are built from
I have one list view and two list. I am loading one list(List list1)
I have an expandable list view I am using in one xml file which
I have a ListView which sometimes I need to put around 10000 items in.

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.