ListView of the countdown in the implementation of the problem collection

Source: Internet
Author: User

About the implementation of the countdown to Android, for many people has been a headache, of course, I also, in the development countdown function will encounter a lot of difficult or even exotic problems or bugs, I in the development countdown, if the current page only a countdown, then it is not very complicated, The effect of development is not very bad, there will be a lot of tutorials to achieve online. If you want to achieve the countdown in the ListView or GridView, it is really a headache, I have suffered a lot in this and walked a lot of detours, there are many dead brain cells. Let me summarize the question of the countdown to the ListView development.

Let's take a look at the diagram I developed, which was implemented in the GridView:

One: Data chaos

Describe what is called data chaos, for example, I have 20 countdown in the running, the first is over, the other is not over, I slipped down, found that some of the following countdown has been over, and then the cycle of sliding, and different countdown to the end, Then there are times when the countdown to the end of the clock begins to Countdown, which is the problem of data chaos that is triggered during the slide.

Two: The countdown begins again:

Describe what is called countdown restart, such as my ListView's first item in the countdown, starting from 60 seconds to reduce, when reduced to if 40 seconds, I slide down, so that the first item beyond the visible screen, and then slide back to the first item, At this time you will find the countdown starts again from 60 seconds countdown, this is because your countdown to die, in the sliding back of the interface redraw, the data reload, so the countdown began again countdown.

Three: cotton, timeout, or even crash:

This is not to describe, the countdown to a lot of words, will appear in the cotton situation, if very much, the phone will crash, I download other well-known app existence countdown interface for use, has been pulling load more data, there are a lot of countdown, found that will be Kaka, the final interface can not operate the crash.

Four: The countdown is not easy to control and judge:

Since the countdown, then we need to listen to the countdown when the end, the end of the corresponding operation, this is one. Second, we need a flexible use of the countdown, such as display "year", "Day", "Time", "Minutes", "seconds", "millisecond" and so on, are better control and modify the best.

To solve these problems, in fact, is very difficult, I have looked up many ways to achieve the findings are not very good, or even solve the problem. Finally, I found a third-party dependency library, on the GitHub, I can not find the specific address, but also in the IT Blue Panther, which

In the use of this way to achieve the countdown, only to solve the third and fourth problems, to tell the truth about the cotton and control aspects of the solution is much better. In addition, I found in the use of the first and second problem, of course, in his project also has a demo in the ListView, but a bit complicated I do not have in-depth research, According to the most basic inheritance baseadapter and viewholder optimization implementation of the way to develop data confusion and restart the bug, and finally I was wondering whether the countdown time can be converted into local time countdown, the final result is completely OK, but there may be a little error, The magic is that the bugs that go with the data are gone.

For example, the countdown takes 100 seconds, then I take the local time plus these 100 seconds as the end time, and then when the countdown needs to start, take this end time minus local time is the time to Countdown.

The specific code is as follows:

The specific code is as follows:

local time: Long curtime = System.currenttimemillis ();//Note: unit milliseconds
End time: Curtime + (100*1000);//Note: In per millisecond, convert 100 seconds to milliseconds
Start the countdown where the countdown is needed:

Cv_countdownview.start (Itemdata.getendtime ()-System.currenttimemillis ());
At the same time, in terms of listening, this dependency provides an interface:

The code is as follows:


Cv_countdownview.setoncountdownendlistener (New Countdownview.oncountdownendlistener () {
@Override public void OnEnd (Countdownview cv) {
End of Time}
});

It is also very simple to use in the layout,

<cn.iwgang.countdownview.countdownview
Android:id= "@+id/cv_countdownview_one"
Android:layout_width= "90DP"
android:layout_height= "30DP"
Android:layout_gravity= "Center_horizontal"
App:isshowday= "false"
App:isshowhour= "false"
App:isshowmillisecond= "true"
App:isshowminute= "true"
App:isshowsecond= "true"
app:suffixgravity= "Center"
App:suffixtextcolor= "#FFFFFF"
App:suffixtextsize= "14SP"
App:timetextcolor= "#FFFFFF"
App:timetextsize= "14SP"/>;

Write to true what you want to show, or false.

I think the most important thing is fluent not cotton.

OK, this is my countdown to the development of the problem summary, I hope to help more people. Thank you, this article is a word I typed, reproduced please specify. Thank you

Original from: http://blog.it985.com/16781.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.