I would like to set a different ID for each of my elements in this ArrayList. It is a recyclerview.
public void createExampleList() {
mExampleList = new ArrayList<>();
mExampleList.add(new exempleitem(R.drawable.ic_android, "Line 1", "Line 2"));
mExampleList.add(new exempleitem(R.drawable.ic_baseline_beach_access_24, "Line 3", "Line 4"));
mExampleList.add(new exempleitem(R.drawable.ic_baseline_airplanemode_active_24, "Line 5", "Line 6"));
}
I want this so i can add a OnClickListener for each of the items, in order to open different activities.
mAdapter.setOnItemClickListener(new ExampleAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position) {
if (position == 0) context.startActivity(new Intent(context, ActivityOne.class));
else if (position == 1) context.startActivity(new Intent(context, ActivityTwo.class));
else if (position == 2) context.startActivity(new Intent(context, ActivityThree.class));
else context.startActivity(new Intent(context, ActivityFour.class));
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.