2010-12-13 5 views
0

doInBackground 메서드에서 tabbar를 추가하고 android에서 예외가 발생합니다. 아무에게도이 작업을 수행 할 수 있습니까? 예를 든다. 내 코드는 다음과 같습니다 : 지금까지 내가 생각doInBackground 메서드에서 tabbar를 추가하면 android에서 예외가 발생합니다.

package com.inquest; 


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.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); 
    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) { 



    try 
     { 


     Resources res = getResources(); 
     TabHost.TabSpec spec; 
     TabHost tabHost=getTabHost(); 

     TabWidget tabWidget = tabHost.getTabWidget(); 
     //TabHost tabHost=(TabHost)this.findViewById(R.) 
     //TabHost tabHost = (TabHost)this.findViewById(R.id.) 


     // tabHost.setBackgroundResource(R.color.gray1); 
    //tabWidget.setBackgroundResource(R.color.gray1); 
     //tabWidget.setBackgroundDrawable(res.getDrawable(R.drawable.quest_tab_bar_icon)); 
     //tabWidget.setBackgroundColor(R.color.gray1); 
     //tabWidget.setBackgroundDrawable(getResources().getDrawable(R.drawable.tabbar)); 
     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; 
      //return parservalue; 
     } 

} 


} 
+0

당신이 얻는 예외와 예외가 어디서 발생했는지 (아마도 예외의 스택 추적도 포함)를 말하면 도움이 될 것입니다. – Nailuj

답변

1

, 추가 탭이 당신 캔트 백그라운드 작업에서 할 UI 스레드/ 에서이 작업을 수행해야합니다. DoInBackground 메서드에서 모든 탭을 추가하고 있습니다.

+0

그러면 탭 표시 줄이로드 될 때까지 스플래시 화면을 표시하는 방법 – mohan

+0

모든 탭을로드하는 데 시간이 많이 걸리지 않습니다. 탭을 직접 표시 할 수 있습니다. 그래도 시작 화면을 표시해야하는 경우 ViewSwitcher를 사용할 수 있습니다. –

관련 문제