为什么我的OnLongClickListener不能正常工作

时间:2017-02-17 14:34:38

标签: android

subList是一个自定义视图适配器,代码如下所示。为什么它不起作用?

代码:

TimeTableSubjectAdapter subList = new TimeTableSubjectAdapter(this,words);

ListView drawList = (ListView)findViewById(R.id.SubjectsDragList);

drawList.setAdapter(subList);
drawList.setClickable(true);
drawList.setLongClickable(true);
drawList.setOnLongClickListener(new View.OnLongClickListener() {

    @Override
    public boolean onLongClick(View view) {
        Log.e("TextView:","Picked up");
        ClipData data = ClipData.newPlainText("","");
        View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
        view.startDrag(data,shadowBuilder,view,0);
        return false;
    }
});

1 个答案:

答案 0 :(得分:0)

我认为你需要处理项目点击,而不是ListView一般

    drawList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            ...
        }
    });