I have implemented a ViewPager using PagerAdapter, now in the PagerAdpater I have the following which works fine:
@Override
public Object instantiateItem(ViewGroup container, final int position) {
ImageView imgDisplay, ivRateBar;
TextView tvName, tvPhoneNumber, tvRate;
inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.viewpager_item, container,false);
tvName = (TextView) viewLayout.findViewById(R.id.tvName);
tvName.setText(_textNames.get(position));
....
Now I have a button in the PagerAdapter, I can get the position of item clicked (in this case the name) by calling:
_textNames.get(position)
Now this works well when the buttons are within the PagerAdapter but I want my buttons to be within the MainActivity instead so that the view pager doesn't scroll the buttons (they should be fixed) now I am not sure how to get the position of the item clicked from MainActivity, I tried:
Toast.makeText(getApplicationContext(), "clicked: "+ViewPagerAdapter._textNames.get(position), Toast.LENGTH_SHORT).show();
but this doesn't work because my MainActivity does not recognize position from .get(position).