2016-06-29 2 views
0
import android.os.Bundle; 
    import android.support.v7.app.AppCompatActivity; 
    import android.view.LayoutInflater; 
    import android.view.View; 
    import android.widget.FrameLayout; 

    public class framelayout extends AppCompatActivity { 

    View imagelayout,itemlayout,recycle_layout; 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.frame_layout); 
      FrameLayout frm1=(FrameLayout)findViewById(R.id.frame2); 
      FrameLayout frm2=(FrameLayout)findViewById(R.id.frame3); 
      FrameLayout frm3=(FrameLayout)findViewById(R.id.frame4); 
      LayoutInflater inflater = getLayoutInflater(); 
      imagelayout=inflater.inflate(R.layout.imagelayout,null); 
      itemlayout=inflater.inflate(R.layout.itemlayout,null); 
      recycle_layout=inflater.inflate(R.layout.recycle_layout,null); 
      frm1.addView(imagelayout); 
      frm2.addView(itemlayout); 
      frm3.addView(recycle_layout); 

      images_activity img=new images_activity(); 
      img.findViewById(R.id.frame2); 



     } 

    } 
    import android.os.Bundle; 
    import android.support.v4.app.FragmentActivity; 
    import android.support.v4.view.ViewPager; 

    public class images_activity extends FragmentActivity { 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.imagelayout); 
      CustomPagerAdapter mCustomPagerAdapter = new CustomPagerAdapter(this); 

      ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); 
      mViewPager.setAdapter(mCustomPagerAdapter); 


     } 


    } 

import android.content.Context; 
import android.support.v4.view.PagerAdapter; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 


public class CustomPagerAdapter extends PagerAdapter { 

    Context mContext; 
    LayoutInflater mLayoutInflater; 

    int[] mResources = {R.drawable.first,R.drawable.second,R.drawable.third,R.drawable.forth}; 
    public CustomPagerAdapter(Context context) { 
     mContext = context; 
     mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public int getCount() { 
     return mResources.length; 
    } 

    @Override 
    public boolean isViewFromObject(View view, Object object) { 
     return view == ((LinearLayout) object); 
    } 

    @Override 
    public Object instantiateItem(ViewGroup container, int position) { 
     View itemView = mLayoutInflater.inflate(R.layout.images_item, container, false); 

     ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView); 
     imageView.setImageResource(mResources[position]); 

     container.addView(itemView); 

     return itemView; 
    } 

    @Override 
    public void destroyItem(ViewGroup container, int position, Object object) { 
     container.removeView((LinearLayout) object); 
    } 
} 

これは完全なコードです。 1つのフレームレイアウトの必要性が画像slideshow.iを持っているそれはうまく動作している私のコードをチェックしているが、それがフレームレイアウトに追加されると、いずれかが私を助けることができない場合は動作していません。3つのフレームレイアウトを持つレイアウトを作成しています。それぞれに1つのフラグメントがあり、動的に最初のフラグメントに追加する必要があります。画像スライドが表示されます。

答えて

0

フラグメント取引をどこで行いますか?

FragmentOne fragmentOne = new FragmentOne(); 
    FragmentManager fragmentManager = getSupportFragmentManager(); 
    FragmentTransaction fragmentTransaction =  fragmentManager.beginTransaction(); 
    fragmentTransaction.replace(R.id.frame1,fragmentOne); 
    fragmentTransaction.commit(); 
+0

これは試しても動作しません。ヌルIDです。 –

+0

エラーとしてフラグメントを示します。 –

+0

私のプロジェクトに適したサンプルプロジェクトを私に提案することができます –

関連する問題