feed
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),"position is "+ position, Toast.LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(), DetailActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.d("listview", "variables: "+ ((Location2) places.get(position)).getName()+" ");
Log.d("listview", "variables: "+ ((Location2) places.get(position)).getImage()+" ");
Log.d("listview", "variables: "+ ((Location2) places.get(position)).getDiscription()+" ");
i.putExtra("name", ((Location2) places.get(position)).getName());
i.putExtra("pic", ((Location2) places.get(position)).getImage());
i.putExtra("disc", ((Location2) places.get(position)).getDiscription());
getApplicationContext().startActivity(i);
}
});
所有数据都存在并打印在日志中,但新活动仅在位置0时开始
答案 0 :(得分:0)
您的问题不太清楚。如果您仅在位置0上显示Toast消息,则似乎仅在您单击位置0时调用onItemClick
方法。
也许,正如马可的建议,你可以试试这个:
feed
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(view.getContext(), "position is " + position, Toast.LENGTH_SHORT).show();
Intent i = new Intent(view.getContext(), DetailActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.d("listview", "variables: " + ((Location2) places.get(position)).getName() + " ");
Log.d("listview", "variables: " + ((Location2) places.get(position)).getImage() + " ");
Log.d("listview", "variables: " + ((Location2) places.get(position)).getDiscription() + " ");
i.putExtra("name", ((Location2) places.get(position)).getName());
i.putExtra("pic", ((Location2) places.get(position)).getImage());
i.putExtra("disc", ((Location2) places.get(position)).getDiscription());
view.getContext().startActivity(i);
}
});