I am working on an application which has a ViewPager view in it, I have created a PagerAdapter, which has the view, instantiateItem() method of PagerAdapter is called twice in create() i don't know why, can anyone help me with this?
Here is my code,
View PagerView;
MyPagerAdapter adapter;
ViewPager pager;
adapter = new MyPagerAdapter();
pager.setAdapter(adapter);
pager.setCurrentItem(0);
public class MyPagerAdapter extends PagerAdapter {
@Override
public Object instantiateItem(final View collection, final int position) {
Log.d("Inside", "Pager");
PagerView = new View(collection.getContext());
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PagerView = inflater.inflate(R.layout.tablemenu, null, false);
tbMenuDetails = (TableLayout) PagerView
.findViewById(R.id.Menutable1);
scrollview = (ScrollView) PagerView.findViewById(R.id.scrollView1);
tbMenuDetails.removeAllViews();
removeTableRows();
createTableLayout(position);
String str[][] = datasource.GetSubMenuDetailsFromMenuId(MenuIdlst
.get(position).trim());
Log.d("Str", "" + str.length);
for (int i = 0; i < str.length; i++) {
addRows(str[i][1], str[i][2], str[i][0], str[i][3], position);
Log.d("Message", "Pos " + position + " SubMenuName" + str[i][2]
+ " SubMenuId" + " " + str[i][0] + " TypeID" + " "
+ str[i][3]);
}
// View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(PagerView, 0);
return PagerView;
}
@Override
public void destroyItem(final View arg0, final int arg1,
final Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public boolean isViewFromObject(final View arg0, final Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public void finishUpdate(View arg0) {
// TODO Auto-generated method stub
}
@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
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return MenuIdlst.size();
}
}
Please help
position
before you do anything – Creeper