I'm trying to alter some sample code I found. It's a one on one chat application but all commands are delivered and read by a buffered reader's br.readLine();
. I need to alter that and instead of (within a while loop) wait for the user to input text in the console (via br.readLine();), but rather to wait for the enter key on an edit text to be entered.
My code sample that I have so far is :
String command;
while(true) {
try {
command=br.readLine();
} catch (IOException e) {
System.err.println("Error reading command");
if(pendingChatAccept) {
sendThroughSocket(Constants.Client.CHAT_DENY, clientSocket, pendingAcceptClient.getIP(), pendingAcceptClient.getPort()); //deny the request
pendingChatAccept=false;
pendingAcceptClient=null;
}
continue;
}
if(pendingChatAccept) {
char c=command.charAt(0);
if(c=='y')
{
System.out.println("\nRequest Accepted. Type 'm' to send a message.");
sendThroughSocket(Constants.Client.CHAT_ACCEPT, clientSocket, pendingAcceptClient.getIP(), pendingAcceptClient.getPort()); //accept the request
currentChatPartner=pendingAcceptClient;
currentlyChatting=true;
pendingChatAccept=false;
pendingAcceptClient=null;
msgQueue.clear(); //clear message queue
} else {
System.out.println("\nRequest Denied.");
sendThroughSocket(Constants.Client.CHAT_DENY, clientSocket, pendingAcceptClient.getIP(), pendingAcceptClient.getPort()); //deny the request
pendingChatAccept=false;
pendingAcceptClient=null;
}
So instead of waiting at command=br.readLine();
, I'd like to wait till a command has been read from the edittext. Is there a way to do this??
I've been struggling for two days now and just can't seem to get it to work.