我有一個活動與Recyclerview項目,在AnotherActivity中,我有很多片段。單擊回收站視圖時,AnotherActivity片段應打開, 請幫助!從AnotherActivity調用片段到MainActivity
*這是回收站適配器從活動 編輯的代碼包括
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
final Item item = itemList.get(position);
holder.name.setText(item.getName());
// Picasso.with(mContext).load(item.getPic()).into(holder.imageView);
holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
int pos = holder.getAdapterPosition();
@Override
public void onClick(View view) {
// Toast.makeText(mContext, "Hello" + item.getName(), Toast.LENGTH_SHORT).show();
switch (pos) {
case 0:
// Toast.makeText(mContext, "zero", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(mContext, WebSlider.class);
mContext.startActivity(intent);
break;
case 1:
//call particular fragment
...........
}
}
}
與viewpager
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_slider);
fm = getSupportFragmentManager();
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
Viewpager適配器另一個活動...
public void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new Chapter1(), "");
adapter.addFragment(new Chapter2(), "");
adapter.addFragment(new Chapter3(), "");
viewPager.setAdapter(adapter);
}
public class ViewPagerAdapter extends FragmentPagerAdapter {
........................
}
發佈您的回收站適配器和活動代碼 –
您是否在其他活動中使用了選項卡布局? –
我已添加適配器和活動代碼.. –