Android RecyclerView OnItemTouchListener无法正常运行

时间:2016-12-18 21:15:45

标签: android android-recyclerview

我有RecyclerView显示数据列表。我想要做的是当用户点击该项目时,它会询问他们是否希望取消该用户的链接。我已经在应用程序的各个方面完成了这项工作,并且已根据功能齐全的RecyclerView OnItemTouchListener编写了此代码,但由于某种原因,拒绝注册任何点击是完全没有问题的。数据填充RecyclerView罚款,它不会让我点击。我错过了一些明显的东西吗?

public void configurePage() {
    Log.d(TAG, "test = " + listOfIDs.size());
    mLayoutManager = new LinearLayoutManager(AgentViewUsers.this);
    mAdapter = new AgentUserViewAdapter(listOfItems);
    mRecyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), mRecyclerView, new RecyclerItemClickListener() {
        @Override
        public void onClick(View view, int position) {
            AlertDialog.Builder build = new AlertDialog.Builder(AgentViewUsers.this);
            build.setTitle("Unlink this user?");
            build.setMessage("Are you sure you wish to unlink this user?");
            build.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // database code that deletes that user from firebase.
                }
            });
            build.setPositiveButton("No", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
        }

        @Override
        public void onLongClick(View view, int position) {

        }
    }));
    mRecyclerView.addItemDecoration(new DividerItemDecoration(AgentViewUsers.this,DividerItemDecoration.VERTICAL_LIST));
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mAdapter);
    spinner.setVisibility(View.GONE);
    // for loop that populates listOfItems from an already populated listOfIDs;
}

1 个答案:

答案 0 :(得分:1)

好吧,你可能想在那个AlertDialog上调用show()。也许你正在使用列表项的自定义布局,并且该布局没有针对不同状态的不同drawable(即,按下,释放)