D
D
DARKENN2019-09-24 18:22:41
Java
DARKENN, 2019-09-24 18:22:41

How to prevent sending messages only with spaces?

buttonSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendText = findViewById(R.id.textMessage);
                sndText = sendText.getText().toString();

                if (sndText.equals("") || sndText.equals(" ") || sndText.equals("   ")) {
                    Toast minLength = Toast.makeText(getApplicationContext(), "Сообщение не может быть пустым!", Toast.LENGTH_SHORT);
                    minLength.show();
                } else {
                    FirebaseDatabase.getInstance().getReference().child("chat").child("messages").push().setValue(new Message(sendText.getText().toString(),
                            nameU));
                    sendText.setText("");
                }
            }
        });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cheypnow, 2019-09-24
@DARKENN

if (sndText.trim().isEmpty()) {
   // ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question