English 中文(简体)
我怎么能够用手来在2个秘密和5个之后改变图像观察的情景?
原标题:How I can use a handler to change the ImageView s picture after 2 sec, and 5?
  • 时间:2011-07-04 21:15:03
  •  标签:
  • android

我有《图像评论》,其中显示了一种情况。 我试图用透镜,但并没有改变情况。 然后,我尝试了手铐,但却没有处理睡觉的方法,因此我不得不增加时间、时间。 我如何能够做到这一点? 请举一个例子吗?

我的原始法典如下:

@Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
                Thread timer = new Thread() {
                    public void run() {
                        int time = 0;
                        while (time <= 7000) {
                            try {
                                sleep(100);
                                time =+ 100;
                                if(time == 2000) {
                                    radar.setImageResource(R.drawable.radar_full);
                                }
                                if(time == 5000) {
                                    radar.setImageResource(R.drawable.radar_50);
                                }
                                if(time == 7000) {
                                    radar.setImageResource(R.drawable.radar_found);
                                }
                            } catch (InterruptedException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();


        }
};
                    timer.start();
                    };
                };
最佳回答

这里是你们的两门辅导:

rel=“nofollow”A Stitch in Time

It appears that you need to learn more about Threads and Handlers in general. However, it s worth pointing out that you cannot update a UI element from within a Thread, which is what I m guessing you tried to do; UI updating (such as changing the content of an ImageView) must be done within the UI thread. Therefore, updating the image inside a Handler on the UI thread was going in the right direction. You just need a way to call that Handler at timed intervals, and the tutorial above demonstrates one such way, by simply posting messages to the Handler.

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签