check if an item is the same than the last i clicked / listview
What i want to do is "simple", i click on an item in the listview, something happen . I click again on an item and depending on if it's the same item i clicked or another one it would do something else . Can you guys help me ?
public OnItemClickListener listener = new OnItemClickListener() {
int i = 1;
int p;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id){
loaddetails(pf, position);
i++;
p=position;
if(i%2 == 0 ){
details.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.enter));
details.setVisibility(View.VISIBLE);
}else{
details.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade2));
details.setVisibility(View.GONE);
}
}
};
My example is something like, i click on an item, details appears, details must disappears only if i click 开发者_如何学Goon the same item .
Keep an id placeholder of the last item clicked:
Global to the class:
int lastID = -1;
Then:
public OnItemClickListener listener = new OnItemClickListener() {
int i = 1;
int p;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id){
loaddetails(pf, position);
i++;
p=position;
if(lastID == id || lastID == -1){
details.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.enter));
details.setVisibility(View.VISIBLE);
}else{
details.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade2));
details.setVisibility(View.GONE);
}
lastID = id;
}
};
精彩评论