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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:32:40+00:00 2026-05-26T09:32:40+00:00

I have a GridView with four columns, on each item I added my library

  • 0

I have a GridView with four columns, on each item I added my library background (a shelf styled one), but the problem is, on the last line if there’s less than four itens, the background goes only until the last item, I need it to fill the row, how can I do that?

That’s my actual code:

public class LibraryGridView extends GridView {
    private LibraryActivity activity;

    public LibraryGridView(LibraryActivity activity) {
        super(activity);
        setBackgroundColor(Color.rgb(223, 223, 223));

        this.activity = activity;

        setNumColumns(activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 6 : 4);
    }

    public void setData(List<LibraryItem> books) {
        setAdapter(new BookAdapter(getContext(), books));
    }

    private class BookAdapter extends ArrayAdapter<LibraryItem> {
        private List<LibraryItem> books;

        public BookAdapter(Context context, List<LibraryItem> books) {
            super(context, 0, books);
            this.books = books;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            BookGridView view = null;

            if (convertView == null)
                view = new BookGridView(activity);
            else
                view = (BookGridView) convertView;

            view.setBackgroundResource(R.drawable.background_grid);
            view.loadStateFrom(getItem(position));

            return view;
        }

        public LibraryItem getItem(int id) {
            return books.get(id);
        }

        public int getCount() {
            return books.size();
        }

        public long getItemId(int position) {
            return position;
        }
    }
}
  • 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-26T09:32:40+00:00Added an answer on May 26, 2026 at 9:32 am

    I think you have to add empty item at the last of private List<LibraryItem> books in multiple of 4 and then pass it to array adapter, so yout list contain (n%4 = 0) item.

    Here usage of 4 because your gridview has a 4 columns.

    Thanks.

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

Sidebar

Related Questions

I have an ASP.NET GridView that has four columns. The first three are typical
I have GridView with CheckBox in it's header and another one in each row:
I have a GridView with 4 columns and I would like to edit one
I have gridview with four columns . All the data inside is generated in
I have one DataTable which has four columns such as MileStoneID MileStoneName Percentage SeqNbr
I have one datatable which has four or five columns. I dont know exactly
I have gridview, it's datasource is list<string> and I added one checkbox column to
I have a GridView where one column is bound to an object property containing
I have a gridview with dropdownlist in it. When the user changes the item
I have gridview with 15 and above columns, I need to freeze the header

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.