Alexandru Mihai Alexandru Mihai - 25 days ago 14
Android Question

Android button click strange behavior

I have a problem with

Button
and
EditText
in Android.Here is my code:

sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isOnline()) {
if(Subject.getText().toString().trim().equals("")){
Subject.setError( "Subject is required!" );
return;
}
if(Body.getText().toString().trim().equals("")){
Body.setError( "Body is required!" );
return;
}
final ProgressDialog progDailog = ProgressDialog.show(
getActivity(), "Send email", "Sending.....", true);
new Thread() {
public void run() {
try {
int result = emailService.sendEmail(spinner.getSelectedItem().toString(),
Subject.getText().toString(),
Body.getText().toString()
);
switch(result){
case 1:
getActivity().runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getActivity(), "Email send successfully!", Toast.LENGTH_LONG).show();
}
});
break;
case -1:
getActivity().runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getActivity(), "Request Error !", Toast.LENGTH_LONG).show();
}
});
break;
}
} catch (Exception e) {
}
progDailog.dismiss();
}
}.start();
}else{
Toast.makeText(getActivity(), "Please check your network connection... !", Toast.LENGTH_LONG).show();
}
}
});


My problem is this one : If I enter in
Body
edittext a text like
stackoverflow
it's works perfectly and email service is called.But,if I enter text like
stack overflow
with space,
ProgressDialog
doesn't appear and email service isn't called.

Thanks in advance.

Answer

From your followup comment (code still not provided) you need to escape the URI before making your HTTP Post call - escaping the text will replace " " with %20 and allow spaces in the subject and body.

Comments