如何在单击按钮时获得进度条?
我正在开发一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果获取 rss feed 需要一些时间,您可以在 NewActivity 中显示 ProgressDialog:
从以下代码中获取帮助:
希望您能理解上面的代码在做什么。稍微定制一下并使用...:)
You can show the ProgressDialog in the NewActivity if it takes some time in getting rss feeds:
take help from the following code:
Hope you can understand what the above code is doing. Customized it a bit and use...:)