1

Ребята,помогите! У меня есть список в котором находится два слушателя:setOnItemClickListener и setOnItemLongClickListener. Проблема состоит в том, что при зажатии на каком-либо элементе списка у меня должен выполняться setOnItemLongClickListener, но выполняется два слушателя(setOnItemClickListener и setOnItemLongClickListener). Как мне исправить данную проблему?Нужно чтобы при зажатии выполнялся только setOnItemLongClickListener.

public void readLobby() {
//        progressDialog.setMessage("Загрука...");
//        progressDialog.show();
        names = new ArrayList<String>();
        user = FirebaseAuth.getInstance().getCurrentUser();
        adapterList = new FirebaseListAdapter<LobbyInfo>(getActivity(), LobbyInfo.class, R.layout.lobby_list_item,
                FirebaseDatabase.getInstance().getReference().child("lobby")) {
            @Override
            protected void populateView(View v, LobbyInfo model, int position) {
                TextView name = (TextView) v.findViewById(R.id.lobby_list_items);
                TextView mess = (TextView) v.findViewById(R.id.lobby_list_mess);
                ImageView lock=(ImageView)v.findViewById(R.id.lock);

                name.setText(model.getName());

                if (model.getMessages() != 0) {
                    mess.setText("+" + String.valueOf(model.getMessages()));
                } else {
                    mess.setText("");
                }

                names.add(model.getName());
                if(!model.getPassword().isEmpty()){
                    lock.setVisibility(v.VISIBLE);
                }
                if(model.getPassword().isEmpty()){
                    lock.setVisibility(v.INVISIBLE);
                }
            }
        };
//        progressDialog.dismiss();
        list.setAdapter(adapterList);

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                TextView textV = (TextView) v.findViewById(R.id.lobby_list_items);
                String str = textV.getText().toString();

                DatabaseReference db = FirebaseDatabase.getInstance().getReference().child("lobby").child(str);
                db.addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        LobbyInfo lobbyInfo = dataSnapshot.getValue(LobbyInfo.class);
                        if (!lobbyInfo.getPassword().isEmpty()) {
                            alertDialogLobbyPass(lobbyInfo.getPassword(), lobbyInfo.getName());
                        } else {
                            Fragment yfc = new Chat();
                            Bundle bundle = new Bundle();
                            bundle.putString("tag", lobbyInfo.getName());
                            yfc.setArguments(bundle);
                            FragmentManager fragmentManager = getFragmentManager();
                            fragmentManager.beginTransaction().replace(R.id.frame, yfc, "Chat").addToBackStack(null).commit();
                        }
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });

            }
        });

        list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
                TextView textV = (TextView) v.findViewById(R.id.lobby_list_items);
                String str = textV.getText().toString();
                alertChange(str);
                return false;
            }
        });
    }

1 ответ 1

4

Поменяй return false; в setOnItemLongClickListener на return true;

1
  • помогло!Спасибо)
    – shcherbuk
    31 мая 2017 в 11:03

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.