0

在我的应用程序中,我正在使用两个选项卡,一个选项卡应用程序联系人,另一个是所有联系人,在应用程序中打开一个选项卡到另一个选项卡,它需要 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"));   


        }
    });





}




   }

请参阅此代码,请告诉如何在选项卡更改为另一个时添加progressDialog ...

4

4 回答 4

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();
         }
     }
于 2013-06-28T10:49:07.617 回答
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。

于 2013-06-28T10:50:23.713 回答
0

由于您正在使用TabActivity(并且您尚未发布您的工作),所以,我猜您已经使用过

  1. TabActivity
  2. 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();
    }

}

并且,AsyncTaskonCreate()您的Activity.

new ContactLoadAsync().execute();

于 2013-06-28T11:52:01.180 回答
0

使用可见性开/关在屏幕中心显示进度条

于 2013-06-28T10:46:08.880 回答