本文介绍了Android的:不能同时设置:setOnItemClickListener setOnScrollListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class MyActivity extends Activity implements OnScrollListener,  OnItemClickListener {
...
listView.setOnItemClickListener(this);
listView.setOnScrollListener(this);  // why not work with previous line?
...

添加ListView.setOnScrollListener后(本)

After adding ListView.setOnScrollListener(this)

onItemClick(...)不再触发。

onItemClick(...) no longer triggered.

有人知道为什么吗?

感谢。

推荐答案

我不明白为什么它不应该工作,

I don't see why it shouldn't work,

试试这个:

  getListView().setOnScrollListener(onAnswersScrolled);
  getListView().setOnItemClickListener(onAnswerClicked);


private OnItemClickListener onAnswerClicked = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // 
                Intent i = new Intent();

                setResult(RESULT_OK, i);
                finish();
        }

    };

    private OnScrollListener onAnswersScrolled = new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // not used
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
            // do something
            }
        }
    };

这篇关于Android的:不能同时设置:setOnItemClickListener setOnScrollListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 00:09