簡體   English   中英

如何在Android Studio中的xml文件中定義長型變量

[英]how to define long type variable in xml file in Android studio

我一直在Android Studio .java文件中編寫此代碼,以計算任務的時間:

long startTime = System.currentTimeMillis();
doLongThing();
long difference = System.currentTimeMillis() - startTime;
long fulltime = difference /1000;
Resources res = getResources();
String text = String.format(res.getString(R.string.The_Time), fulltime);

我將此行添加到我的string.xml中:

<string name="The_Time"> The process took $fulltime </string>

在“活動”主目錄中的此textview:

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/button"
    android:text="@string/The_Time"/>

但是我一直在這張照片中得到結果。 我究竟做錯了什么? 不顯示毫秒數。

嘗試通過以下方式使用字符串值:

<string name="The_Time"> The process took %1$d </string>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM