I am trying to implement a Dave Smith PagerContainer to show multiple pages in my ViewPager. I introduced a click listener to display page numbers, but when I click on the left page, the message "clicked on item 2" is displayed (position 0 will be correct). If I click on the middle and right pages, the correct messages are displayed, "paragraph 1" and "paragraph 2" respectively. I also added an image to describe the problem. How can i fix this? Thanks in advance.

The following is a snippet of code:
@Override public Object instantiateItem(ViewGroup container, final int position) { TextView view = new TextView(PagerActivity.this); view.setText("Item "+position); view.setGravity(Gravity.CENTER); view.setBackgroundColor(Color.argb(255, position * 50, position * 10, position * 50)); view.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast.makeText(PagerActivity.this, "clicked on Item " + String.valueOf(position), 1000).show(); } }); container.addView(view); return view; }
pager.setOffscreenPageLimit(adapter.getCount()); pager.setPageMargin(15); pager.setClipChildren(false);
android android-viewpager
burakk Oct 26 '12 at 12:33 2012-10-26 12:33
source share