Android ListView shield part Item click event

To be a record, in general, as long as we deal with the ListView click event when only mListView.setOnItemClickListener () can be, but sometimes some special needs, some Item is not necessary to add a click event, such as a task list I, which is not task to jump to the corresponding page, click on the task is not completed at this time how to deal with? This article documents the following:

We rewrite the following two methods can be realized in the demand Adapter

 public boolean areAllItemsEnabled() {
     return false;// 所有的Item不可点击

 public boolean isEnabled(int position) {
     // 该位置判断的一个状态,比如栗子中的“已完成/未完成”
     // 也可以根据位置进行拦截,第一条Item不可点击为:if (position == 0) {
     if (mList.get(position).isStatus()) {
         return false;// 符合条件的Item不可点击
     } else {
         // 拦截事件交给上一级处理
         return super.isEnabled(position);

As a result the page setOnItemClickListener do not have to deal with if and else up.

Published 59 original articles · won praise 88 · views 190 000 +

Guess you like