我有一个项目列表视图。现在我想构建一个OnItemClickListener。如果用户单击该项目,则会启动新的活动。 Actvity在put.Extra Methode上给出一个带有imagePaths的ArrayList,用于在同一个地方加载图片。但如果我点击项目,不同的图片正在加载。这是代码
MyCompositionView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
int count = 0;
ArrayList<String> tmpImgPath = new ArrayList<String>();
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
for (int i = 0; i < myList.size(); i++) {
count++;
for (int j = 0; j < count; j++) {
tmpImgPath.add(myList.get(i).imgPath.get(j));
}
}
if (count == 3) {
Intent intent = new Intent(MyCompositionsListActivity.this, LayoutForThreeActivity.class);
intent.putExtra("imgPaths", tmpImgPath);
startActivity(intent);
}
}
});
我认为我的for循环出了问题!
答案 0 :(得分:0)
MyCompositionView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
int count = 0;
ArrayList<String> tmpImgPath = new ArrayList<String>();
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//for (int i = 0; i < myList.size(); i++) {
// count++;
//for (int j = 0; j < count; j++) {
// tmpImgPath.add(myList.get(i).imgPath.get(j));
//}
//}
// if (count == 3) {
Intent intent = new Intent(MyCompositionsListActivity.this, LayoutForThreeActivity.class);
intent.putExtra("imgPaths", myList.get(position).imgPath);
startActivity(intent);
// }
}
});