本地化进度对话框
我显示了一个带有异步任务的进度对话框。
private class RetrieveTask extends AsyncTask<String, Void, String>
{
RetrieveTask t = this;
ProgressDialog d = null;
@Override
protected void onPreExecute()
{
// TODO
//d = ProgressDialog.show(context, "", context.getString(R.string.querying_server), true, true, new DialogInterface.OnCancelListener() {
d = ProgressDialog.show(context, "", "Loading...", true, true, new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
t.cancel(true);
}
});
// continues....
到此阶段,context
已设置为根 Activity。
我想本地化该消息,如“TODO”后面的评论中所示。为此,我需要获取字符串资源;我如何最好地从这里做到这一点?
I show a progress dialog with an asynchronous task.
private class RetrieveTask extends AsyncTask<String, Void, String>
{
RetrieveTask t = this;
ProgressDialog d = null;
@Override
protected void onPreExecute()
{
// TODO
//d = ProgressDialog.show(context, "", context.getString(R.string.querying_server), true, true, new DialogInterface.OnCancelListener() {
d = ProgressDialog.show(context, "", "Loading...", true, true, new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
t.cancel(true);
}
});
// continues....
By this stage context
has been set to the root activity.
I'd like to localise the message as indicated in the comment following the "TODO". To do this I need to get at the strings resource; how do I best do this from here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我缺少一个
getResources()
调用,仅此而已。context.getResources().getString(R.string.my_string_id);
I'm missing a
getResources()
call, that's all.context.getResources().getString(R.string.my_string_id);
我只是使用对调用活动上下文的引用。
伪代码示例:
I just use a reference to the calling activities context.
Example pseudo-code: