开发者

Custom ListView: separator entries ignore settings

I've created a custom ListView with separators (using this tutorial). It looks and works fine but the separators are still clickable, focusable and able to get a context menu called from. So i've tryied to "shut them up":

...
case TYPE_SEPARATOR:
    convertView.setFocusable(false);
    convertView.setClickable(false);
    convertView.setLongClickable(false);
    break;
        }

开发者_运维技巧return convertView;

But they totally ignore these settings! For testing purposes i used covertView.setBackground(Color.MAGENTA) and it works well. Anyone got an idea what could be wrong?


Assuming your adapter is one that implements BaseAdapter (such as an ArrayAdapter), override the isEnabled() method in the adapter.

@Override
public boolean isEnabled(int position) {
    if (getItemViewType(postion) == TYPE_SEPARATOR) {  // method taken from example
        return false;
    }
    return super.isEnabled(position);
}

To keep track of which items are separators and which are not, keep an ArrayList or some other type of collection that keeps track.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜