在我的应用程序中,我使用两个标签,一个标签应用程序联系人,另一个是所有联系人,在应用程序中打开一个标签到另一个标签,它会粘贴10sce,在那个时候如何添加相同类型的消息,如加载屏幕等,
请告诉我如何在我的Android应用程序中执行此操作?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabview);
final TabHost tabHost = getTabHost();
TextView txtTab = new TextView(this);
txtTab.setText("Mobell Contacts");
txtTab.setPadding(8, 9, 8, 9);
txtTab.setTextColor(Color.WHITE);
txtTab.setTextSize(14);
//txtTab.setTypeface(localTypeface1);
txtTab.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
TabHost.TabSpec spec;
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("tab1").setIndicator(txtTab).setContent(new Intent(this, ContactList.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
tabHost.addTab(spec);
TextView txtTab1 = new TextView(this);
txtTab1.setText("All Contacts");
txtTab1.setPadding(8, 9, 8, 9);
txtTab1.setTextColor(Color.WHITE);
txtTab1.setTextSize(14);
//txtTab.setTypeface(localTypeface1);
txtTab1.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
TabHost.TabSpec spec1;
// Initialize a TabSpec for each tab and add it to the TabHost
spec1 = tabHost.newTabSpec("Tab2").setIndicator(txtTab1).setContent(new Intent(this, TabAct2.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
tabHost.addTab(spec1);
tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#101010"));
tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#848284"));
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#848284"));
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#181418"));
}
});
}
}
看到这段代码plz告诉我们如何在tab将其中一个更改为其他时添加progressDialog ...
答案 0 :(得分:1)
您可以使用AsyncTask最佳方式显示加载屏幕...
onCreate()
{
dialog.show();
new LoadData().execute(null);
}
--------------------------------------------------------------------------
private class LoadData extends AsyncTask<URL, Integer, Boolean> {
protected Long doInBackground(URL... urls) {
// your code to load data here <------
return true;
}
protected void onPostExecute(Boolean result) {
dialog.dismiss();
}
}
答案 1 :(得分:1)
你可以做这样的事情来展示进步 -
public class MainActivity extends Activity {
Button b;
ProgressBar pb1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button)findViewById(R.id.button1);
pb1 = (ProgressBar)findViewById(R.id.progressBar1);
}
public void click(View v){
new Thread("thread1"){
public void run(){
try{
for(int i=0; i<10; i++)
{
Thread.sleep(4000);
pb1.setProgress(i*10);
}
}
catch(InterruptedException e){
e.printStackTrace();
}
};
}.start();
}
}
如果您想要显示消息,请使用Spinner。
答案 2 :(得分:0)
使用可见性开启/关闭在屏幕中心显示进度条
答案 3 :(得分:0)
由于你正在使用TabActivity
(而你尚未发布你的工作),所以,我猜你已经使用了
TabActivity
Activity
(对于两个标签)现在,当您从一个标签切换到另一个标签时,您实际上正在调用Activity
。因此,只需在AsyncTask
中创建一个需要时间加载的Activity
。例如,
class ContactLoadAsync extends AsyncTask<Void, Void, Void> {
ProgressDialog pd;
@Override
protected void onPreExecute()
pd = ProgressDialog.show(YourActivity.this, "title", "loading", true, false);
}
@Override
protected Void doInBackground(Void... params) {
// call your contact loading functions here
return null;
}
@Override
protected void onPostExecute(Void result) {
pd.dismiss();
}
}
并且,在AsyncTask
的{{1}}中调用此onCreate()
。
Activity