2010-12-13 66 views
1

我有一个登录页面从登录,如果用户点击登录按钮,它会去tabactivity。在选项卡活动中,我有四个选项卡:主页,股票等。从Tabactivity我称为活动组嵌套活动。从活动组我称之为家庭活动。在家中,我加载标签栏并调用web服务和解析值,并在主页选项卡中加载家庭活动。这需要时间。我如何避免黑屏?任何人都可以举个例子吗?我尝试了很多,但它不工作。如果任何知道,请给代码。 在第二项活动中,我将标签栏加载到标签加载并调用Web服务。我必须展示一些启动画面。显示黑屏从一个活动到另一个活动几分钟

我在doInBackground方法中加入tabbar,它是正确的吗?

import java.util.ArrayList; 

//import com.inquest.LoginActivity.FetchTask; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.ProgressDialog; 
import android.app.TabActivity; 
import android.content.Context; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.content.res.Resources; 
import android.graphics.Typeface; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.os.Handler; 
import android.os.Message; 
import android.util.Log; 
import android.view.Gravity; 
import android.view.Window; 
import android.widget.Button; 
import android.widget.RelativeLayout; 
import android.widget.TabHost; 
import android.widget.TabWidget; 
import android.widget.TextView; 
import android.widget.TabHost.TabSpec; 
//TabActivity 

public class HelloTabWidget extends TabActivity 
{ 
    int width =40; 
    int height =49; 
    //private TabHost tabHost; 
    TextView txthome; 
    TextView txtstock; 
    TextView txtcitn; 
    TextView txtmyquest; 
    Button btn; 
    //private ProgressDialog pd = null; 
    private ProgressDialog dlg; 
    private Object data = null; 
    String strusername=""; 
    String strPassWord=""; 
    String questGroupId=""; 
    String userid=""; 
    String systemuserid=""; 
    String providerid=""; 
    private ProgressDialog dialog; 
public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
     setProgressBarIndeterminateVisibility(true); 
    setContentView(R.layout.tab); 






    new TabTask(HelloTabWidget.this).execute(null); 

//} 

} 





public class TabTask extends AsyncTask<Void, Void,Void> 
{ 
     private ProgressDialog dlg; 
      private Context ctx; 
     public TabTask(Context context) { 
      ctx = context; 
     } 




     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      dlg = new ProgressDialog(HelloTabWidget.this); 
      dlg.setMessage("Loading...."); 
      dlg.show(); 
     } 



     @Override 
     protected Void doInBackground(Void... params) { 
      // TODO Auto-generated method stub 
      try 
      { 
       TabHost.TabSpec spec; 
       TabHost tabHost=getTabHost(); 
       TabWidget tabWidget = tabHost.getTabWidget(); 
       Resources res = getResources(); 

                Typeface myTypeface = Typeface.createFromAsset(ctx.getAssets(),"verdanab.TTF"); 
       Typeface myTypeface1 = Typeface.createFromAsset(ctx.getAssets(),"verdana.TTF"); 
       Intent homeintent; 
       // Create an Intent to launch an Activity for the tab (to be reused) 
       homeintent = new Intent(); 
       Bundle bundle=getIntent().getExtras(); 
       String strusername=bundle.get("strUserName").toString(); 
       String strPassWord=bundle.get("strPassword").toString(); 
       String questGroupId=bundle.get("questGroupId").toString(); 
       String userid=bundle.get("userid").toString(); 
       String systemuserid=bundle.get("systemuserid").toString(); 
       String providerid=bundle.get("providerid").toString(); 
        Log.d("home activity username", strusername); 
       Log.d("home activity password", strPassWord); 
       Log.d("home activityquestGroupId",questGroupId); 
        homeintent.setClass(ctx, HomeActivityGroup.class); 
        homeintent.putExtra("strUserName", strusername); 
        homeintent.putExtra("strPassWord",strPassWord); 
        homeintent.putExtra("questGroupId",questGroupId); 
        homeintent.putExtra("userid",userid); 
        homeintent.putExtra("systemuserid", systemuserid); 
        homeintent.putExtra("checking", "one"); 

        spec = tabHost.newTabSpec("home").setIndicator("Home",res.getDrawable(R.drawable.home_tab_bar_icon)).setContent(homeintent); 
       tabHost.addTab(spec); 

       //homeintent = new Intent().setClass(this,ThemeSearchActivity.class); 
       homeintent = new Intent().setClass(ctx,StockActivity.class); 
       homeintent.putExtra("strUserName", strusername); 
       homeintent.putExtra("strPassWord",strPassWord); 
       homeintent.putExtra("questGroupId",questGroupId); 
       homeintent.putExtra("userid",userid); 
       homeintent.putExtra("systemuserid", systemuserid); 
       homeintent.putExtra("providerid", providerid); 
       spec = tabHost.newTabSpec("stock").setIndicator("Stock",res.getDrawable(R.drawable.stocks_tab_bar_icon)).setContent(homeintent); 
       tabHost.addTab(spec); 
       homeintent = new Intent().setClass(ctx,ArticleActivity.class); 
        spec = tabHost.newTabSpec("citn").setIndicator("CITN",res.getDrawable(R.drawable.citn_tabbar_icon)).setContent(homeintent); 
       tabHost.addTab(spec); 
       homeintent = new Intent().setClass(ctx, MyCompaniesActivity.class); 
       spec = tabHost.newTabSpec("myquest").setIndicator("My Quest",res.getDrawable(R.drawable.quest_tab_bar_icon)).setContent(homeintent); 
       tabHost.addTab(spec); 

       for (int i =0; i < tabWidget.getChildCount(); i++) { 
        //tabWidget.getChildAt(i).setBackgroundColor(R.color.black); 
         tabWidget.getChildAt(i).getLayoutParams().height = height; 
       tabWidget.getChildAt(i).getLayoutParams().width = width; 
       RelativeLayout relLayout = (RelativeLayout)tabWidget.getChildAt(i); 
       TextView tv = (TextView)relLayout.getChildAt(1); 
       tv.setTextSize(10.0f); 
       //tv.setCompoundDrawablesWithIntrinsicBounds(0, 1, 0, 0); 
       tv.setTypeface(myTypeface1);   



      } 
      } 
       catch (Exception e) { 
       // TODO: handle exception 
        e.printStackTrace(); 
      } 

      return null; 
     } 

    } 


} 
+0

您可以在不同的线程中调用Web服务并使用进度条避免黑屏。 – 2010-12-13 11:47:55

+0

你可以举例 – mohan 2010-12-13 12:24:28

回答

3

您需要在Tabbar活动中实现AsyncTask功能。

private class LongOperation extends AsyncTask<String, Void, String> { 

@Override 
    protected void onPreExecute() { 
    // Things to be done before execution of long running operation. For example showing ProgessDialog 
    } 

    @Override 
    protected String doInBackground(String... params) { 
     // perform long running operation operation 
     return null; 
    } 

    @Override 
    protected void onPostExecute(String result) { 
     // execution of result of Long time consuming operation 
    } 

    @Override 
    protected void onProgressUpdate(Void... values) { 
     // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog 
    } 
} 
+0

在第二个活动中,我正在调用活动组中的活动组,我正在调用另一个活动。第二个活动中调用webservices – mohan 2010-12-13 12:42:31

1

我也有同样的问题,但我的问题是通过将这个属性的活动解决:

[Activity(Theme = "@android:style/Theme.Translucent.NoTitleBar")] 

试试吧。

0

这很简单只要不在onCreate()方法中调用任何长时间运行的任务,它就会阻止您的活动创建,直到任务完成。

只是在此方法下定义UI任务并调用onStart()或onResume()方法中的任何其他调用。

尽量让您的oncreate()方法尽可能精简。

相关问题