Note that there are some explanatory texts on larger screens.

plurals
  1. PObutton.PerformClick() causing text to clear
    text
    copied!<p>I have an activity where a user sends messages to another user, I created an onKey listener to send messages when a user pressed enter as well.</p> <p>When a user actually clicks the send button, everything works perfectly, when a user presses the enter button a blank message is sent.</p> <p>Here is the onkeylistener code <strong>Code:</strong></p> <pre><code> messageText.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == 66) { sendMessageButton.performClick(); return true; } return false; } }); </code></pre> <p>and this is the sendmessagebutton <strong>Code:</strong></p> <pre><code> sendMessageButton.setOnClickListener(new OnClickListener() { CharSequence message; Handler handler = new Handler(); @Override public void onClick(View arg0) { // android.text.format.DateFormat df = new // android.text.format.DateFormat(); message = messageText.getText(); String messageSent = DateFormat.format("dd MMM yy, kk:mm", new java.util.Date()).toString();// java.text.DateFormat.getDateTimeInstance().format("yyyy-MM-dd kk:mm:ss"); if (message.length() &gt; 0) { appendToMessageHistory(imService.getUsername(), message.toString(), messageSent); ((ScrollView) findViewById(R.id.scrollView)) .fullScroll(View.FOCUS_DOWN); localstoragehandler.insert(imService.getUsername(), friend.userName, message.toString(), messageSent); messageText.setText(""); Thread thread = new Thread() { @Override public void run() { try { if (imService.sendMessage( imService.getUsername(), friend.userName, message.toString()) == null) { handler.post(new Runnable() { @Override public void run() { Toast.makeText( getApplicationContext(), R.string.message_cannot_be_sent, Toast.LENGTH_LONG).show(); // showDialog(MESSAGE_CANNOT_BE_SENT); } }); } } catch (UnsupportedEncodingException e) { Toast.makeText(getApplicationContext(), R.string.message_cannot_be_sent, Toast.LENGTH_LONG).show(); e.printStackTrace(); } } }; thread.start(); } } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload