这是“入职”视图。如图像[1]所示。当我滑动另一个项目时也会显示。我在入职活动布局中也做了按钮。现在,我要按下按钮以拨打与所示项目对应的电话号码。如何根据入职项目从数组中获取数据?
private OnBoard_Adapter mAdapter;
private Button call;
private Button email;
ArrayList<OnBoardItem> onBoardItems = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_on_boarding);
onboard_pager = (ViewPager) findViewById(R.id.pager_introduction);
loadData();
mAdapter = new OnBoard_Adapter(this, onBoardItems);
onboard_pager.setAdapter(mAdapter);
onboard_pager.setCurrentItem(0);
onboard_pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
// Load data into the viewpager
public void loadData() { int[] mobile = {R.string.pg_phy_mobile1,
R.string.pg_phy_mobile2,
R.string.pg_phy_mobile3,
R.string.pg_phy_mobile4,
R.string.pg_phy_mobile5,
R.string.pg_phy_mobile6,
R.string.pg_phy_mobile7,
R.string.pg_phy_mobile8,};
int[] email = {R.string.pg_phy_email1,
R.string.pg_phy_email2,
R.string.pg_phy_email3,
R.string.pg_phy_email4,
R.string.pg_phy_email5,
R.string.pg_phy_email6,
R.string.pg_phy_email7,
R.string.pg_phy_email8};
int[] imageId = {R.drawable.avatar,
R.drawable.avatar,
R.drawable.avatar,
R.drawable.avatar,
R.drawable.avatar,
R.drawable.avatar,
R.drawable.avatar,
R.drawable.avatar};
for (int i = 0; i < imageId.length; i++) {
OnBoardItem item = new OnBoardItem();
item.setImageID(imageId[i]);
item.setMobile(getResources().getString(mobile[i]));
item.setEmail(getResources().getString(email[i]));
onBoardItems.add(item);
}
}
}
enter code here
[1]: https://i.stack.imgur.com/8cOLa.jpg