Issue
I have this code
public void serviceUnavailable() {
runOnUiThread(new Runnable() {
@Override
public void run() {
progressBar = new ProgressDialog(context);
progressBar.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
atsSocketManager.disconnect();
progressBar.dismiss();
}
return false;
}
});
progressBar.setCancelable(false);
progressBar.setTitle(R.string.ats_title_wait);
progressBar.setMessage(R.string.ats_unavailable_service);
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.show();
}
});
}
But I am getting an error on line where I am setting the message if I set like this
progressBar.setMessage(R.string.ats_unavailable_service);
The error is this
error: no suitable method found for setMessage(int) method ProgressDialog.setMessage(CharSequence) is not applicable (actual argument int cannot be converted to CharSequence by method invocation conversion) method AlertDialog.setMessage(CharSequence) is not applicable (actual argument int cannot be converted to CharSequence by method invocation conversion)
where I set the title is almost the same and is working
progressBar.setTitle(R.string.ats_title_wait);
If I put the text between comas is working, but I want to understand why this way doesn't work
progressBar.setMessage("Service unavailable");
thank you
Solution
Yes, Because setMessage()
is not designed to get resource string as int.
You have to get String from resource int and apply to setMessage()
using getResource().getString()
method of Application Context.
Like,
progressBar.setMessage(context.getResources().getString(R.string.ats_unavailable_service));
Answered By - user370305
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.