如何在单击按钮时获得进度条?

发布于 2024-11-11 13:27:05 字数 1126 浏览 3 评论 0原文

我正在开发一个 Android 应用程序,在其中通过单击“确定”按钮从编辑文本框中获取字符串后,我已将字符串从一个活动传递到另一个活动。该字符串是一个提供 rss 提要的 url。所以它需要加载它需要一点时间。我想显示一个进度条以保持界面交互。如何在单击同一按钮时实现进度条或进度对话框?

我的活动代码片段是

 EditText Urlis=(EditText)findViewById(R.id.entry);
    final Button button = (Button) findViewById(R.id.ok);
    final Intent i=new Intent(this , RSSReder.class);
final String choice=Urlis.getText().toString();

    i.putExtra("key", choice);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(i);
        }    
    });  
}

}

下一个活动的代码的某些部分是

公共类RSSReder扩展活动实现OnItemClickListener {

public String RSSFEEDOFCHOICE;
public final String tag = "RSSReader";
private RSSFed feed = null;


/** Called when the activity is first created. */

public void onCreate(Bundle abc) {
    super.onCreate(abc);
    setContentView(R.layout.next1);


    Intent i = getIntent();
    RSSFEEDOFCHOICE =i.getStringExtra("key");

    // go get our feed!
    feed = getFeed(RSSFEEDOFCHOICE);

    // display UI
    UpdateDisplay();

}

I am developing an android application in which I have passed a string from one activity to another activity, after getting it from a edit text box by clicking on "OK" button.The string is a url which gives a rss feed.So it takes a little bit time to load it .I want to show a progress bar to keep the interface interactive.How can achieve a progress bar or a progress dialog on that same button click?

My code Snippet for activity is

 EditText Urlis=(EditText)findViewById(R.id.entry);
    final Button button = (Button) findViewById(R.id.ok);
    final Intent i=new Intent(this , RSSReder.class);
final String choice=Urlis.getText().toString();

    i.putExtra("key", choice);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(i);
        }    
    });  
}

}

some part of the code of next activity is

public class RSSReder extends Activity implements OnItemClickListener
{

public String RSSFEEDOFCHOICE;
public final String tag = "RSSReader";
private RSSFed feed = null;


/** Called when the activity is first created. */

public void onCreate(Bundle abc) {
    super.onCreate(abc);
    setContentView(R.layout.next1);


    Intent i = getIntent();
    RSSFEEDOFCHOICE =i.getStringExtra("key");

    // go get our feed!
    feed = getFeed(RSSFEEDOFCHOICE);

    // display UI
    UpdateDisplay();

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦过后 2024-11-18 13:27:05

如果获取 rss feed 需要一些时间,您可以在 NewActivity 中显示 ProgressDialog:
从以下代码中获取帮助:

dialog = ProgressDialog.show(mParent,"","Loading,Please wait...", true);

final Thread t=new Thread(new Runnable() {

            public void run() {

                //get your rss feeds here
            }
        });
        t.start();

        Thread t1=new Thread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
                try {
                    t.join();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                new Handler().post(new Runnable() {
                    public void run() {

                        dialog.cancel();
                                           UpdateDisplay();

                    }
                });

            }
        });
        t1.start();

希望您能理解上面的代码在做什么。稍微定制一下并使用...:)

You can show the ProgressDialog in the NewActivity if it takes some time in getting rss feeds:
take help from the following code:

dialog = ProgressDialog.show(mParent,"","Loading,Please wait...", true);

final Thread t=new Thread(new Runnable() {

            public void run() {

                //get your rss feeds here
            }
        });
        t.start();

        Thread t1=new Thread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
                try {
                    t.join();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                new Handler().post(new Runnable() {
                    public void run() {

                        dialog.cancel();
                                           UpdateDisplay();

                    }
                });

            }
        });
        t1.start();

Hope you can understand what the above code is doing. Customized it a bit and use...:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文