0
votes

I am implementing caurosel like view pager by adjusting page margin. I am able to implement like below

enter image description here

but i am facing problem with PagerAdapter

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view= inflater.inflate(R.layout.mylayout, null);

    // 
    Button btn=(Button)view.findViewById(R.id.button1);
    btn.setTag(position);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          Log.e("position",v.getTag()+"");
       }
   }
    return imgView;
}

Though I am setting Tags, I am able to get correct position only for center page (Selected item), but when I click on left side page's button it returns wrong value.

I have searched about this issue lot, I could not find the solution so far.

looking for your help.

Thanks

2

2 Answers

0
votes

You can use RecyclerView

LinearLayoutManager layoutManager = ...
recyclerView.setLayoutManager(layoutManager);

//when you want horizontal
layoutManager.setOrientation(context,LinearLayoutManager.HORIZONTAL,false);

//when you want vertical
layoutManager.setOrientation(context,LinearLayoutManager.VERTICAL,false);
0
votes

There was no issues with PagerAdapter. Actual issue was due to a third party library which i used as wrapper to animate the views.