1

Hello i am trying to get my TabHosts to work with Progress Dialog but i keep getting these errors for loading a ListView in the respective activities but i keep getting these errors.

code:

public class AndroidTabLayoutActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //final ProgressDialog dialog = ProgressDialog.show(getParent(), "Please wait..", "Doing stuff..", true);
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setMessage("Please wait...");
        pd.show();
        Runnable myRun = new Runnable(){
        public void run(){
            Looper.myLooper().prepare();
            //DO EVERYTHING YOU WANT!
            TabHost tabHost = getTabHost();

            // Tab for All
            TabSpec allspec = tabHost.newTabSpec("All");
            allspec.setIndicator("All", getResources().getDrawable(R.drawable.icon_photos_tab));
            Intent allIntent = new Intent(AndroidTabLayoutActivity.this, AllApplicationsActivity.class);           
            allspec.setContent(allIntent);

            // Tab for Installed Application
            TabSpec systemspec = tabHost.newTabSpec("Installed Applications");
            // setting Title and Icon for the Tab
            systemspec.setIndicator("Applications", getResources().getDrawable(R.drawable.icon_videos_tab));
            Intent systemIntent = new Intent(AndroidTabLayoutActivity.this, SystemApplicationsActivity.class);
            systemspec.setContent(systemIntent);


            // Adding all TabSpec to TabHost
            tabHost.addTab(allspec); 
            tabHost.addTab(systemspec); 

            //Finally
            runOnUiThread(new Runnable() {
            public void run() {


            pd.dismiss();
            }
            });
        }
        };

        Thread T = new Thread(myRun);
        T.start();


    }


}

EDIT: now im getting an error when i launch the program

07-26 17:55:05.637: E/AndroidRuntime(25603): FATAL EXCEPTION: Thread-974
07-26 17:55:05.637: E/AndroidRuntime(25603): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4286)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:885)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.View.requestLayout(View.java:12881)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.View.requestLayout(View.java:12881)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.View.requestLayout(View.java:12881)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.View.requestLayout(View.java:12881)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.View.requestLayout(View.java:12881)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.View.requestLayout(View.java:12881)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.ViewGroup.addView(ViewGroup.java:3211)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.view.ViewGroup.addView(ViewGroup.java:3193)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.widget.TabHost.setCurrentTab(TabHost.java:349)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at android.widget.TabHost.addTab(TabHost.java:236)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at com.example.androidtablayout.AndroidTabLayoutActivity$1.run(AndroidTabLayoutActivity.java:43)
07-26 17:55:05.637: E/AndroidRuntime(25603):    at java.lang.Thread.run(Thread.java:856)
07-26 17:55:05.927: D/OpenGLRenderer(25603): Flushing caches (mode 0)
07-26 17:55:05.967: D/OpenGLRenderer(25603): Flushing caches (mode 0)
07-26 17:55:29.132: D/OpenGLRenderer(25603): Flushing caches (mode 2)
07-26 17:55:29.372: D/AndroidRuntime(25603): Shutting down VM
4

1 回答 1

0

代替:

Intent allIntent = new Intent(this, AllApplicationsActivity.class);            
Intent systemIntent = new Intent(this, SystemApplicationsActivity.class);

和:

Intent allIntent = new Intent(AndroidTabLayoutActivity.this, AllApplicationsActivity.class);           
Intent systemIntent = new Intent(AndroidTabLayoutActivity.this, SystemApplicationsActivity.class);

更新第二次崩溃

您的首字母缩写ProgressDialog不正确。

ProgressDialog pd = new ProgressDialog(getContext());
pd.setMessage(...);
pd.show();
于 2012-07-26T09:43:04.667 回答