开发者

check if an item is the same than the last i clicked / listview

开发者 https://www.devze.com 2023-03-17 17:17 出处:网络
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

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;
    }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消