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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:21:06+00:00 2026-06-05T02:21:06+00:00

I have a very basic question about ViewPager. I have a ViewPagerActivity that includes

  • 0

I have a very basic question about ViewPager. I have a ViewPagerActivity that includes 5 pages, where each page has its own layout xml, in addition to the main.xml (see code below) that is referenced in the ViewPagerActivity.java’s setContentView(R.layout.main).

The “middle” page (middle.xml which is one of the 5 layout xml’s) includes a Listview that is dynamically populated with data from a database.

Here is my question. Where should I put the following code that pupulates the Listview and set ClickListener?

mMemoListView = (ListView)findViewById(R.id.list_in_middle_layout);
mMemoListAdapter = new MemoListAdapter(this);
mMemoListView.setAdapter(mMemoListAdapter);
mMemoListView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
         viewMemo(position);
}
   });   

I don’t think it will be in ViewPagerActivity.java, unless it can reference both main.xml and middle.xml through setContentView(). I also thought about adding a java class that will reference middle.xml, but I don’t know how it can be activated(?) when the middle page is inflated. (See MyPageAdapter below to see how each page is inflated.)

Thanks for reading. Please feel free to ask for further clarification.

Here is main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/myfivepanelpager"/>
</LinearLayout>

Here is middle.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff"
>
<RelativeLayout
    android:id="@+id/titleLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="#ffffffff"
    >
    <com.ViewPager.TitleBackgroundButton
        android:id="@+id/titleBackgroundBtn"
             android:layout_width="fill_parent"
    android:layout_height="48dp"
    android:layout_alignParentTop="true"
        android:text="Memo"
        android:textSize="18dp"
        android:textStyle="bold"
        />
</RelativeLayout>
<ListView
    android:id="@+id/list_in_middle_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="4dp"
    android:layout_below="@+id/titleLayout"
    android:layout_above="@+id/buttonLayout"
    android:divider="#00000000"
    android:listSelector="#00000000"
    android:cacheColorHint="#00000000"
    />
<LinearLayout
    android:id="@+id/buttonLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:layout_alignParentBottom="true"
    >
    <LinearLayout
    android:id="@+id/buttonLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
>
<com.ViewPager.TitleBitmapButton
android:id="@+id/newMemoBtn"
android:layout_width="100dp"
android:layout_height="48dp"
android:text="New"
android:textSize="18dp"
android:textStyle="bold"
android:textColor="#ff420000"
/>
<com.ViewPager.TitleBitmapButton
android:id="@+id/closeBtn"
android:layout_width="100dp"
android:layout_height="48dp"
android:layout_marginLeft="20dp"
android:text="Close"
android:textSize="18dp"
android:textStyle="bold"
android:textColor="#ff420000"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Here is ViewPagerActivity.java

public class ViewPagerActivity extends Activity {
/** Called when the activity is first created. */

public static final String TAG = "ViewPagerActivity";
@Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            MyPagerAdapter adapter = new MyPagerAdapter();
            ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
            myPager.setAdapter(adapter);
            myPager.setCurrentItem(2);

    }

    private class MyPagerAdapter extends PagerAdapter {

            public int getCount() {
                    return 5;
            }

            public Object instantiateItem(View collection, int position) {

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

                    int resId = 0;
                    switch (position) {
                    case 0:
                            resId = R.layout.farleft;
                            break;
                    case 1:
                            resId = R.layout.left;
                            break;
                    case 2:
                            resId = R.layout.middle;
                            break;
                    case 3:
                            resId = R.layout.right;
                            break;
                    case 4:
                            resId = R.layout.farright;
                            break;
                    }

                    View view = inflater.inflate(resId, null);

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

                    return view;
            }

            @Override
            public void destroyItem(View arg0, int arg1, Object arg2) {
                    ((ViewPager) arg0).removeView((View) arg2);

            }

            @Override
            public void finishUpdate(View arg0) {
                    // TODO Auto-generated method stub

            }

            @Override
            public boolean isViewFromObject(View arg0, Object arg1) {
                    return arg0 == ((View) arg1);

            }

            @Override
            public void restoreState(Parcelable arg0, ClassLoader arg1) {
                    // TODO Auto-generated method stub

            }

            @Override
            public Parcelable saveState() {
                    // TODO Auto-generated method stub
                    return null;
            }

            @Override
            public void startUpdate(View arg0) {
                    // TODO Auto-generated method stub

            }

    }
  • 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-05T02:21:07+00:00Added an answer on June 5, 2026 at 2:21 am

    You should add it in your switch case in instantiateItem:

    public Object instantiateItem(View collection, int position) {
    
    
                    View view=null;
    
                    LayoutInflater inflater = (LayoutInflater) collection.getContext()
                                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
                    int resId = 0;
                    switch (position) {
                    case 0:
                            resId = R.layout.farleft;
                            view = inflater.inflate(resId, null);
                            break;
                    case 1:
                            resId = R.layout.left;
                            view = inflater.inflate(resId, null);
                            break;
                    case 2:
                            resId = R.layout.middle;
                            view = inflater.inflate(resId, null);
                            ListView memoListView = (ListView)view.findViewById(R.id.list_in_middle_layout);
                            MemoListAdapter memoListAdapter = new MemoListAdapter(this);
                            memoListView.setAdapter(memoListAdapter);
    
                            break;
                    case 3:
                            resId = R.layout.right;
                            view = inflater.inflate(resId, null);
                            break;
                    case 4:
                            resId = R.layout.farright;
                            view = inflater.inflate(resId, null);
                            break;
                    }
    
    
    
                    ((ViewPager) collection).addView(view, 0);
    
                    return view;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic question about PHP. So, there is index.php that includes
I have a very basic question about SVN. I know SVN has pretty strict
I have a very basic question about the LocalMon print monitor found at http://msdn.microsoft.com/en-us/library/windows/hardware/ff556478%28v=vs.85%29.aspx
I have a very basic question about calculating RMSE in an NB classification scenario.
I have a very basic question about how to write to a plist. I
I've got, probably, a very basic question about sessions. In the page load function
I realize that this is probably a very basic question, but I have spent
I have a very basic question about MVC web applications in Java. Since the
I have a very basic question about binding between controls. I have a class
Very basic seeming PHP question here... I have a page to which I'm already

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.