如何在按钮单击时获取进度条?
问题描述:
我正在开发一个android应用程序,其中我从一个活动传递给另一个活动的字符串,从编辑文本框中通过单击“确定”按钮获取它。字符串是一个url,它提供了一个rss feed.So加载它需要一点时间。我想显示一个进度条来保持界面的交互性。如何在同一个按钮上点击一个进度条或进度对话框?如何在按钮单击时获取进度条?
我的活动代码段是
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();
}
答
您可以显示ProgressDialog i ñ如果需要一定的时间在获得的RSS提要NewActivity:从下面的代码 采取的帮助:
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();
希望你能理解上面的代码在做什么。定制它一点,并使用... :)
你是否显示使用来自以前的活动在新类(RSSReader.class)中的url的webview ...? – 2011-06-01 07:16:14
Dinesh我在列表视图中获取新活动中的RSS源 – 2011-06-01 07:22:08
你能发布一些新的活动的代码,你实际上在那里做什么......? – 2011-06-01 07:25:31