2016-05-06 7 views
0

android studioでデフォルトのタブ付きアクティビティを作成しました。 と私はtab1とtab2を使用して2つのビューを表示しようとしました。 LinearLayoutを継承します。 以下はそのコードです(Tab1)。タブ付きのアクティビティで膨らんだレイアウトのビューを表示するには?

public class Tab1 extends LinearLayout { 
    View rootView; 

    public Tab1(Context context) { 
     super(context); 
     init(context); 
    } 

    public Tab1(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(context); 
    } 

    //inflater 
    private void init(Context context) { 
     LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     rootView = inflater.inflate(R.layout.fragment_main_tab1, this, true); 
    } 

    public View getView(){ //getter 
     return rootView; 
    } 
} 

ここで私はデフォルトtabbed activityで作られたonCreateView方法があります。 各タブにtab1、tab2を表示したかったのです。

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

    View rootView; //return view 
    Tab1 tab1 = new Tab1(StaticManager.applicationContext); //inflated activity 
    Tab2 tab2 = new Tab2(StaticManager.applicationContext); //inflated activity 

    if (getArguments().getInt(ARG_SECTION_NUMBER) == 1) { 
     container.addView(tab1); 
     rootView = tab1.getRootView(); 
    } else { 
     container.addView(tab2); 
     rootView = tab2.getRootView(); 
    } 
    return rootView; 
} 

とエラーメッセージがこれである、

05-06 14:36:57.972 19264-19264/kr.eyeballs.mobilecloudchattingapp E/AndroidRuntime: FATAL EXCEPTION: main 
05-06 14:36:57.972 19264-19264/kr.eyeballs.mobilecloudchattingapp E/AndroidRuntime: Process: kr.eyeballs.mobilecloudchattingapp, PID: 19264 
05-06 14:36:57.972 19264-19264/kr.eyeballs.mobilecloudchattingapp E/AndroidRuntime: java.lang.StackOverflowError 

それはうまくいきません。 これをどのように修正する必要がありますか?

私が何を意味するか分からない場合は、私にもっと情報を追加することを教えてください。

答えて

1

あなたが間違ったメソッドを呼び出した場合は、getRootView()の代わりにgetView()を呼び出してください。 stackoverflowの原因ViewGroupのコードの 平和:

/** 
    * @hide 
    */ 
    @Override 
    public void resetResolvedLayoutDirection() { 
     super.resetResolvedLayoutDirection(); 

     int count = getChildCount(); 
     for (int i = 0; i < count; i++) { 
      final View child = getChildAt(i); 
      if (child.isLayoutDirectionInherited()) { 
       child.resetResolvedLayoutDirection(); 
      } 
     } 
    } 
+0

それは働きます!ありがとう:)私はgetRootViewとgetViewの間で混乱していた – eyeballs

関連する問題