2014-11-05 166 views
0
    DateTime startDate8 = DateTime.now(); 
       DateTime endDate8 = new DateTime(2014, 11, 5, 15, 0); 

       Period period8 = new Period(startDate8, endDate8, PeriodType.dayTime()); 

       PeriodFormatter formatter8 = new PeriodFormatterBuilder() 
       .appendMinutes() 
       .toFormatter(); 

       tw.setText(String.valueOf(formatter8.print(period8))); 

我的Android應用程序。如何更改TextView文本

if tw is empty; 
tw="00" 

if tw is one-digit text, one-digit value = "x"; 
tw = "0x" 

tw是TextView中的文本。我想要寫「00」至TW時,總重量爲空 我想要寫的前綴爲「0」至TW當TW是一個數字字符

我解釋http://i.imgur.com/5wBmMI9.png

+0

,我們希望你能證明你的企圖。你是否通過Android文檔搜索?如果是,您發現哪些方法可以幫助您完成此任務? – user2336315 2014-11-05 18:08:46

+0

@ user2336315我編輯了我的代碼 – 2014-11-05 18:13:03

回答

1
if(tws.getText().toString().isEmpty()){ 
tw.setText("00") 
} 

if(tws.getText().toString().equals("x")){ 
tw.setText("0x") 
} 
+0

好的代碼,但是一位數的值不是x。一位數值可以是1,2,3,4,5,6,7,8,9 – 2014-11-05 18:23:31

+1

我會使用String.format(「%02d」,num)而不是條件 – Lukas 2014-11-05 18:31:59

+0

我應該計算數字在tw – 2014-11-05 18:34:08