一个按钮后,等待图片图标是pressed [英] Image icon for waiting after a button is pressed

查看:234
本文介绍了一个按钮后,等待图片图标是pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,当用户presses一个按钮,可以查看图像长得更高的网络。其他那些屏幕是其他的活动。由于许多图像是很多KBS,这需要一些时间来加载,我需要的东西,会通知用户,他有pressed按钮,必须等待的时间。我试图用一个微调,但我couldn'tmake为我的XML处理,所以你可以建议我什么吗?许多Android应用只是有一个黑色的屏幕,直到最终视图被加载,或者例如使按钮改变backgrounf颜色提示用户有pressed它,必须等待。而凡在code,我必须把它?

下面是我的code。

  b4.setOnClickListener(新View.OnClickListener(){
                公共无效的onClick(查看L){
                    / * ParnassosTheme(); * /
                    我的意图=新IntentScreen.this,OtherScreen.class);
                    束B =新包();
                    b.putString(ID,身份证);
                    i.putExtras(二);
                    startActivity(ⅰ);
            }
            });

和我的其他屏幕活动

 公共无效的onCreate(捆绑savedInstanceState){
            super.onCreate(savedInstanceState);
...做的事情......


解决方案

在你加载任务在任务开始时显示进度对话框,关闭它当工作完成。注意:它工作正常,但onCreateDialog()已经去precated <一个href=\"http://developer.android.com/reference/android/app/Activity.html#onCreateDialog%28int,%20android.os.Bundle%29\"相对=nofollow>此处信息。如果您的定位SDK 11+考虑用DialogFragment而不是这里阅读。

 公共类OtherScreen延伸活动{
    私有静态最终诠释LOADING_DIALOG_KEY = 0;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){        super.onCreate(savedInstanceState);        //初始化        //显示加载对话框
        的ShowDialog(LOADING_DIALOG_KEY);        新LoadDataTask()执行();
    }    @覆盖
    保护对话框onCreateDialog(INT ID){        ProgressDialog对话框= NULL;        如果(ID == LOADING_DIALOG_KEY){            对话框=新ProgressDialog(本);
            dialog.setTitle(对话框的标题);
            dialog.setMessage(数据载入中...);
            dialog.setIndeterminate(真);
            dialog.setCancelable(假);
        }        返回对话框;
    }    私人最后一类LoadDataTask扩展
        AsyncTask的&LT;太虚,太虚,太虚&GT;
    {        @覆盖
        保护无效doInBackground(无效... PARAMS)
        {
            //不要在这里工作
            返回null;
        }        @覆盖
        保护无效onPostExecute(虚空结果)
        {
            dismissDialog(LOADING_DIALOG_KEY);
        }
    }
}

I have an application that when a user presses a button, can view images frow web. Those other screens are in other activities. Because many images are many kbs, and it takes some time to load, I need something that will inform the user, that he has pressed the button and must waits. I tried using a spinner but i couldn'tmake it work for my xml, so can you suggest me anything else? Many android apps just have a black screen until the final view is loaded, or for example make the button change backgrounf color suggesting that the user has pressed it and must wait. And where in the code must I place it?

Here is my code.

b4.setOnClickListener(new View.OnClickListener() {
                public void onClick(View l) {
                    /*ParnassosTheme();*/
                    Intent i = new IntentScreen.this,OtherScreen.class);
                    Bundle b = new Bundle();
                    b.putString("id", id);
                    i.putExtras(b);
                    startActivity(i);
            }
            });

and my other screen activity

public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
...do things...

解决方案

When you do loading task show a progress dialog in the beginning of the task and dismiss it when work is done. Note: it works fine but onCreateDialog() is already deprecated info here. If you targeting SDK 11+ consider to use DialogFragment instead read here.

public class OtherScreen extends Activity{
    private static final int LOADING_DIALOG_KEY = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        // initialization

        // show loading dialog
        showDialog(LOADING_DIALOG_KEY);

        new LoadDataTask().execute();
    }

    @Override
    protected Dialog onCreateDialog(int id){

        ProgressDialog dialog = null;

        if (id == LOADING_DIALOG_KEY){

            dialog = new ProgressDialog(this);
            dialog.setTitle("Dialog title");
            dialog.setMessage("Data loading...");
            dialog.setIndeterminate(true);
            dialog.setCancelable(false);
        }

        return dialog;
    }

    private final class LoadDataTask extends 
        AsyncTask<Void, Void, Void>
    {

        @Override
        protected Void doInBackground(Void... params)
        {
            // do work here
            return null;
        }

        @Override
        protected void onPostExecute(Void result)
        {
            dismissDialog(LOADING_DIALOG_KEY); 
        }
    }
}

这篇关于一个按钮后,等待图片图标是pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆