在android标签布局中显示进度对话框 [英] Show a progress dialog in android tab layout
问题描述
我需要在单击选项卡的同时显示进度对话框
I need to show a progress dialog, while clicking a tab,
我的代码ID
public class SIPTabWidget extends TabActivity{
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
final Resources res = getResources(); // Resource object to get Drawables
final TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ListContacts.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost
.newTabSpec("contacts")
.setIndicator("",
res.getDrawable(R.drawable.tab_contacts))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Dialer.class);
spec = tabHost
.newTabSpec("dialer")
.setIndicator("", res.getDrawable(R.drawable.tab_dial))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Favorites.class);
spec = tabHost
.newTabSpec("favorites")
.setIndicator("", res.getDrawable(R.drawable.tab_favorites))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, org.sipdroid.sipua.ui.Settings.class);
spec = tabHost
.newTabSpec("settings")
.setIndicator("", res.getDrawable(R.drawable.tab_settings))
.setContent(intent);
tabHost.addTab(spec);
}
当我单击设置"选项卡时,在给定的oncreate中调用了设置活动"
when i click the settings tab, Setting activity is called, in its oncreate i gave
final ProgressDialog dialog = ProgressDialog.show(getParent(), "Please wait..", "Doing stuff..", true);
dialog.setCancelable(false);
dialog.show();
对我来说,在显示设置"布局之前需要花费一些时间来加载布局,因此在此之前,我需要显示ProgressDialog,表示单击设置"选项卡时的时间,并且我需要关闭选项卡更改为设置时显示对话框
for me before showing the Settings layout its taking some time to load the layout, so before that i need to show the ProgressDialog, means the time when i click the Settings tab and i need to dismiss the Dialog when the tab changes to Settings
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
System.out.println(" Tab ID: "+tabId);
if(tabId.equals("dial")){
dialog .dismiss();
}
}
});
Settings.class
Settings.class
public class Settings extends PreferenceActivity implements OnSharedPreferenceChangeListener, OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("Settings oncreate");
final ProgressDialog dialog = ProgressDialog.show(getParent(), "Please wait..", "Doing stuff..", true);
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
dialog.dismiss();
}
};
Thread t = new Thread() {
public void run() {
//send message
handler.sendEmptyMessage(0);
}
};
if (Receiver.mContext == null) Receiver.mContext = this;
addPreferencesFromResource(R.xml.preferences);
setDefaultValues();
Codecs.check();
t.start
}
推荐答案
每个选项卡都是一个活动...我想what is taking time
在设置活动中...
Well each tab is an activity... I suppose that what is taking time
is in the settings activity...
将其放置在设置活动中:
Put this in the setting activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ProgressDialog dialog = ProgressDialog.show(getParent(), "Please wait..", "Doing stuff..", true);
dialog.setCancelable(false);
dialog.show();
Runnable myRun = new Runnable(){
public void run(){
Looper.myLooper().prepare();
//DO EVERYTHING YOU WANT!
//Finally
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.dismis();
}
});
}
};
Thread T = new Thread(myRun);
T.start();
记住:在您run()
在此块中
//DO EVERYTHING YOU WANT!
如果需要更改界面,则必须使用
If anything needs to change the UI, you must do it using
runOnUiThread(new Runnable() {
@Override
public void run() {
//DO IT
}
});
这篇关于在android标签布局中显示进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!