2016-04-01 36 views
0

複数のフレームを使用してアプリケーションデータをロードしたいと考えています。私はただ知りたい、これを行う正しい方法は何か。フレームレイアウトを使用するか、フラグメントを使用する必要があります。私はまた、私のアプリでナビゲーション引き出しを使用しています。複数のレイアウトを使用してデータをロードする

@Override 
    public boolean onNavigationItemSelected(MenuItem item) { 
     // Handle navigation view item clicks here. 
     int id = item.getItemId(); 
     FragmentManager fragmentManager = getFragmentManager(); 

     if (id == R.id.homepage) { 
      Intent homepage = new Intent (MainActivity.this, MainActivity.class); 
      startActivity(homepage); 
          // Handle the camera action 
     } else if (id == R.id.foodpage) { 
      //handle the food page here 
      fragmentManager.beginTransaction() 
        .replace(R.id.content_frame 
          , new FirstFragment()) 
        .commit(); 

     } else if (id == R.id.schedulepage) { 
      fragmentManager.beginTransaction() 
        .replace(R.id.content_frame 
        , new ScheduleFragment()) 
        .commit(); 

     } else if (id == R.id.emotionspage) { 
      fragmentManager.beginTransaction() 
        .replace(R.id.content_frame 
        , new EmotionsFragment()) 
        .commit(); 

     } else if (id == R.id.basicneedspage) { 
      fragmentManager.beginTransaction() 
        .replace(R.id.content_frametwo 
        , new BasicneedsFragment()) 
        .commit(); 

     } else if (id == R.id.exit) { 
      askBeforeExit(); 

     } 

答えて

2

フラグメントを使用する方がよいでしょう。フラグメントはメインスレッドの負荷を軽減します。フレームレイアウトの場合と同様に、多くのことを管理する必要があります。

+0

今、私はフレームレイアウトを使用しています。問題は両方のフレームが同時にデータを表示していることです。 –

0

同じアクティビティで複数のレイアウトを扱う場合、このような種類のレイアウトには、LayoutInflaterを使用してみてください。

+0

LayoutInflaterのメソッドやコードを教えてください。私はどのように私のメインファイルに実装することができます。 –

+0

LinearLayout item =(LinearLayout)findViewById(R.id.layoutitem); View child = getLayoutInflater()。inflate(R.layout.childlayout、null); item.addView(子); –

+0

ここでは、2つのレイアウトファイルを別々に作成する必要があります。メインJavaファイルで設定された可視性メソッドを設定できますか? –

関連する問題