我需要在点击标签
时显示进度对话框我的代码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中我给出了
final ProgressDialog dialog = ProgressDialog.show(getParent(), "Please wait..", "Doing stuff..", true);
dialog.setCancelable(false);
dialog.show();
对我来说,在显示“设置”布局之前需要一些时间来加载布局,所以在此之前我需要显示ProgressDialog,表示时间当我点击“设置”选项卡时我需要关闭选项卡更改为设置
时的对话框tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
System.out.println(" Tab ID: "+tabId);
if(tabId.equals("dial")){
dialog .dismiss();
}
}
});
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
}
答案 0 :(得分:5)
每个标签都是一个活动......我想what is taking time
在设置活动中......
将其放入设置活动:
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!
如果需要更改UI,则必须使用
执行此操作 runOnUiThread(new Runnable() {
@Override
public void run() {
//DO IT
}
});
答案 1 :(得分:1)
您可以使用android的asyntask功能来显示进度对话框,请参阅此http://developer.android.com/reference/android/os/AsyncTask.html
答案 2 :(得分:1)
答案 3 :(得分:0)
如果getParent()不适合您,请尝试仅使用TabsActivity.context
(或替换父标签活动类的名称)。我正在使用嵌套活动,因此使用getParent()仍然没有为对话框返回正确的上下文。
在尝试了上述建议的20种不同变体后,我更换了这一行:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
使用:
AlertDialog.Builder builder = new AlertDialog.Builder(TabsActivity.context);
它就像一个魅力。您还需要在TabsActivity类中创建上下文变量。类似于onCreate方法中的public static TabsActivity context;
和context=this
。