当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How to enter numbers and format in real time into "mm:ss.S"

问题描述:

I'm writing a timing/pacing app for runners. A key feature of the app is being able to enter in a goal time.

I know I'll be able to accomplish my goal using an editText for each minutes, seconds, and milliseconds section, but that would be a pain for me and the user. The idea I have in my head is like entering an alarm time, like in the timely app (I tried to post an image but I don't have enough reputation). The string would begin as "--:--.-" and get filled from the right as numbers are entered.

Thanks in advance!

网友答案:

Use String.format() to fill it for example, if your data is an Integer:

String time;
    if(!(minute==0 && second==0 && miliSecond==0))
        time = String.format("%02d:%02d.&1d",mminute,second,miliSecond);
    else 
      time="--:--.-";
分享给朋友:
您可能感兴趣的文章:
随机阅读: