首页 \ 问答 \ 如何在Java中连接后设置XML字符串?(How to set XML string after concat'ing in Java?)

如何在Java中连接后设置XML字符串?(How to set XML string after concat'ing in Java?)

所以我按照这里的文档将XML字符串值与其他东西连接起来,结果得到以下代码:

//XML strings.xml
<string name="start_next_act_string">The next activity has been scheduled to automatically launch in %1$d seconds!</string>

//layout/activity_home.XML
    <TextView
        android:text="@string/start_next_act_string"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

//Home.java inside class, but outside oncreate
int startNextActivityInSeconds = 10;

//Home.java inside class and inside oncreate
        super.onCreate(savedInstanceState);

        Resources res = getResources();
        String text = String.format(res.getString(R.string.start_next_act_string), startNextActivityInSeconds);

        setContentView(R.layout.activity_home);

但是在Android屏幕上会打印出来

下一个活动已安排在%1 $ d秒内自动启动!

而不是

下一个活动已安排在10秒内自动启动!

如何更新XML字符串以显示连续的字符串结果?


So I've followed the documentation here to concatenate XML string values with other things, and as a result have the following code:

//XML strings.xml
<string name="start_next_act_string">The next activity has been scheduled to automatically launch in %1$d seconds!</string>

//layout/activity_home.XML
    <TextView
        android:text="@string/start_next_act_string"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

//Home.java inside class, but outside oncreate
int startNextActivityInSeconds = 10;

//Home.java inside class and inside oncreate
        super.onCreate(savedInstanceState);

        Resources res = getResources();
        String text = String.format(res.getString(R.string.start_next_act_string), startNextActivityInSeconds);

        setContentView(R.layout.activity_home);

However on the Android screen it prints out

The next activity has been scheduled to automatically launch in %1$d seconds!

rather than

The next activity has been scheduled to automatically launch in 10 seconds!

How do I update XML string such that it displays the concat'd string result?


原文:
更新时间:2022-04-11 12:04

最满意答案

您将需要使用IsolatedStorage ,例如:

放在文件顶部:

using System.IO.IsolatedStorage;

然后在你的方法中这样做:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var istream = new IsolatedStorageFileStream("File.txt", FileMode.OpenOrCreate, store))
    {
        using (var sw = new StreamWriter(istream))
        {
            sw.Write("Some Stuff");
        }
    }
}

这个和其他操作的一个很好的例子和解释可以在这里找到: http//msdn.microsoft.com/en-us/library/cc265154(v = VS.95).aspx#Y300

您可以使用Windows Phone 7 IsolatedStorageExplorer查看IsolatedStorage

一个开始文档的好地方: http//msdn.microsoft.com/library/ff626516(v = VS.92).aspx

也在这里: http//create.msdn.com/en-us/education/documentation


You will need to use IsolatedStorage, for example:

Place at the top of your file:

using System.IO.IsolatedStorage;

Then in your method do this:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var istream = new IsolatedStorageFileStream("File.txt", FileMode.OpenOrCreate, store))
    {
        using (var sw = new StreamWriter(istream))
        {
            sw.Write("Some Stuff");
        }
    }
}

A great example and explanation of this and other operations can be found here: http://msdn.microsoft.com/en-us/library/cc265154(v=VS.95).aspx#Y300

You can look through your IsolatedStorage by using the Windows Phone 7 IsolatedStorageExplorer

A good place to start for documentation: http://msdn.microsoft.com/library/ff626516(v=VS.92).aspx

Also here: http://create.msdn.com/en-us/education/documentation

相关问答

更多
  • 大部分是 - 获取当前位置(cellid,mnc,mmc,lac,lat,lng) 大部分没有 - 读/写/删除/拦截SMS,CallLog,联系人,日历,文件,笔记 否 - 获取已安装的应用程序列表 是 - 使用SQLite 否 - 电子邮件和VPN配置 MOSTLY NO - 能够启用/禁用蓝牙,GPRS,无线网络 是 - 录音 是 - 加密 大多数不 - 控制手机配置文件 是 - JSON 大多数不 - 文件系统通知 MOSTLY YES - Get current location (cellid, ...
  • 我缺少.Net和VS2012扩展的代码合同: .Net的代码合同 - http://www.google.com/url?q=http%3A%2F%2Fvisualstudiogallery.msdn.microsoft.com%2F1ec7db13-3363-46c9-851f-1ce455f66970%3FSRC%3DVSIDE&sa=D&sntz= 1 USG = AFQjCNGLZoTI_GSQJfSfJP5JuSNvv8SlOw 代码合约编辑器扩展VS2012 - http://www.googl ...
  • 是的。 Windows Phone Silverlight 8是Windows Phone 8.1发布后给予Windows Phone 8的名称。 还有Windows Phone Silverlight 8.1和Windows Phone 8.1 。 这两者之间的区别在于Windows Phone 8.1与Windows应用商店应用兼容,而Windows Phone Silverlight 8.1不兼容。 你可以在这里了解更多关于这个: http : //msdn.microsoft.com/en-us/l ...
  • 如果没有看到您的实际代码,很难说出问题所在。 因此,我会提供另一种解决方案,而不是试图读懂你的想法。 我已经在Windows Phone上广泛使用了隔离存储,我已经学到了这一点。 世界上没有库,没有API,没有SDK,没有Web服务,错误报告比Windows手机上的隔离存储更糟糕。 一切都是无效访问或未经授权的访问与ZERO进一步的信息。 为了解决这个问题,我创建了一个DLL,它将对象序列化为隔离存储。 您所要做的就是将[DataContractAttribute]置于您的类名之上,将[DataMemebe ...
  • 它通过将临时文件名更改为原始文件名即字符串tempJpeg来解决 It got solved by changing temporary file name to original file name i.e. string tempJpeg
  • 我不知道性能问题(听起来很奇怪),但根本没有理由在这里使用StreamReader / StreamWriter ,因为您可以在二进制级别进行复制。 事实上,ISO映像不是文本 ,因此将其读入char数据很可能会破坏事物。 有关信息,即使您不想使用File.Copy ,您所需要的只是: using(var inFile = File.OpenRead(source)) using(var outFile = File.Create(destination)) { inFile.CopyTo(outF ...
  • 2014年4月11日发布的新版SQLite(3.8.3.1)应解决任何问题,最后:-)。 到目前为止,我没有遇到过同样的错误,所以我想它现在已经修复了。 http://www.sqlite.org/releaselog/3_8_3_1.html The new version of SQLite (3.8.3.1) that was released on 11th April 2014 should resolve any issues, finally :-) . So far I have not e ...
  • Mango确实是Windows Phone 7.5更新的代号。 Windows Phone 7.5中有许多新的API和功能,它带来了一个新的SDK(版本7.1)。 针对Windows Phone 7.0 SDK的应用在7.1下工作正常,但针对Windows Phone 7.1 SDK的应用需要运行Mango更新。 Windows Phone站点列出了Windows Phone 7.5(Mango更新)中的新功能, MSDN列出了7.0 SDK和7.1 SDK之间的API更改。 Mango was indee ...
  • 由于Windows Phone应用程序是沙箱,因此通常使用Isolated Storage类来保存文件,而不是直接转到System.IO。 但既然你提到了关卡信息(编译到你的应用程序中?),也许以下链接会有所帮助: 如何在WP7应用程序中嵌入和读取文本文件? Since Windows Phone apps are sandboxed, you would typically use the Isolated Storage classes for saving files, and not go dire ...
  • 您将需要使用IsolatedStorage ,例如: 放在文件顶部: using System.IO.IsolatedStorage; 然后在你的方法中这样做: using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var istream = new IsolatedStorageFileStream("File.txt", FileMode.OpenOrCreate, store)) { ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)