Android ListView child View setEnabled() and setClickable() do nothing

前端 未结 4 907
有刺的猬
有刺的猬 2020-11-30 13:12

I\'m doing some AsyncTask work after user clicks an item in my ListView. I\'d like to disable the item so it can\'t be clicked twice. I\'ve simplif

4条回答
  •  遥遥无期
    2020-11-30 13:39

    So, you may be using a custom adapter too. If you do, override these methods:

    public boolean areAllItemsEnabled() {
        return false;
    }
    
    public boolean isEnabled(int position) {
        // return false if position == position you want to disable
    }
    

    Then, when you receive a click tell the adapter what was the last item clicked and return false on isEnabled for that position. For instance, you can have a method like this in your adapter:

    private int mLastClicked;
    public void setLastClicked(int lastClicked){
        mLastClicked = lastClicked;
    }
    

提交回复
热议问题