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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:06:44+00:00 2026-06-08T03:06:44+00:00

I am Implementing a custom Horizontal View Pager. My Intention is to populate the

  • 0

I am Implementing a custom Horizontal View Pager. My Intention is to populate the entries of a particular table in a ListView. The method have to detect how many tables are there in the database and set as many pages for the horizontal view pager. (One Page for One TABLE – Each page contains only one ListView to showing entries of the corresponding TABLE).

Here’s my tries.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewp);
    MyPagerAdapter adapter = new MyPagerAdapter();
    ViewPager myPager = (ViewPager) findViewById(R.id.threepageviewer);
    myPager.setAdapter(adapter);
    DbHelper helper = new DbHelper(this);
    count = helper.countTables();
    myPager.setCurrentItem(count);
    temp = helper.countTables() - 1;
    temp1 = helper.countTables() - 1;
}

here’s the page adapter class.

private class MyPagerAdapter extends PagerAdapter {

    public int getCount() {
        return count;
    }

    public Object instantiateItem(View collection, int position) {

        LayoutInflater inflater = (LayoutInflater) collection.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View view = null;


        if (position == count-1) {
            view = inflater.inflate(R.layout.middle, null);
            ListView list = (ListView) view.findViewById(R.id.listView1);
            helper = new DbHelper(Listing.this);
            String tabName = helper.getTableName(temp1);
            dataset_cursor = helper.getAll(tabName);
            startManagingCursor(dataset_cursor);
            adapter = new NoteAdapter(dataset_cursor);
            list.setAdapter(adapter);
            adapter.notifyDataSetChanged();
        }
        if (position < temp) {
            temp--;
            temp1--;
            // int hg = temp - position;
            // int tempo = temp - hg;
            view = inflater.inflate(R.layout.left, null);
            ListView list1 = (ListView) view.findViewById(R.id.listView1);
            helper = new DbHelper(Listing.this);
            String tabName = helper.getTableName(temp1);
            dataset_cursor1 = helper.getAll(tabName);
            startManagingCursor(dataset_cursor1);
            adapter1 = new NoteAdapter(dataset_cursor1);
            list1.setAdapter(adapter1);
            adapter1.notifyDataSetChanged();
            Toast.makeText(getBaseContext(), tabName, Toast.LENGTH_LONG);
            temp--;
            temp1--;
        }
        if (position > temp) {
            temp++;
            temp1++;
            // int hg = position - temp;
            // int tempo = temp - hg;
            view = inflater.inflate(R.layout.right, null);
            ListView list2 = (ListView) view.findViewById(R.id.listView1);
            helper = new DbHelper(Listing.this);
            String tabName = helper.getTableName(temp1);
            dataset_cursor2 = helper.getAll(tabName);
            startManagingCursor(dataset_cursor2);
            adapter2 = new NoteAdapter(dataset_cursor2);
            list2.setAdapter(adapter2);
            adapter2.notifyDataSetChanged();
        }

        ((ViewPager) collection).addView(view, 0);
        return view;
    }

I want the Last Database Table to be the default page. when I swipe left It should go to the second-last Table and so on. While trying this I almost get what I need. Except this problem .

END—TABLE6–(left swipe)–TABLE5–(left swipe)–TABLE5–(left swipe)–TABLE3–(left swipe)–TABLE2–(left swipe)–TABLE1—END

END—TABLE1–(right swipe)–TABLE2–(right swipe)–TABLE2–(right swipe)–TABLE3–(right swipe)–TABLE4–(right swipe)–TABLE5—END

I am doing it correctly. what could be the mistake here. Is there any other way to implement the same ?

  • 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-08T03:06:45+00:00Added an answer on June 8, 2026 at 3:06 am

    The problem is because of your temp and temp1 variables. Do the following..

    public Object instantiateItem(View collection, int position) {
         ...
         ...
         ListView list = (ListView) view.findViewById(R.id.listView1);
         helper = new DbHelper(Listing.this);
         String tabName = helper.getTableName(position+1);
         dataset_cursor[position] = helper.getAll(tabName);
         startManagingCursor(dataset_cursor[position]);
         adapter = new NoteAdapter(dataset_cursor[position]);
         list.setAdapter(adapter);
         adapter.notifyDataSetChanged();
    
         ((ViewPager) collection).addView(view, 0);
    
         return view;
    }
    

    If you want to maintain multiple dataset cursors then have dataset cursor array declared, which can be easily accessed like dataset_cursor[position] as shown above.

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

Sidebar

Related Questions

I'm a bit confused as to implementing custom view controllers. I have a view
I am implementing my custom table view controller. The issue I am facing is
I'm implementing a custom calendar using a GridView. For this Calendar I have 3
I have built a custom view component that displays a timeline of events. The
I have seen a lot of different ways of implementing custom cells in a
I have a class MyClass . If I serialize it without implementing custom converter
I have a custom template checkbox that I am implementing using a viewbox (using
i'm having difficulties implementing custom widget rendering in a QListView . I currently have
I'm implementing the ValidateUser method on a custom MembershipProvider class. I've seen quite a
I'm currently implementing a custom MultiPageEditorPart where I want to have multiple pages when

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.