android this view's id is no_id,Android Fragment no view found for ID?

I was facing a Nasty error when using Viewpager within Recycler View.

Below error I faced in a special situation.

I started a fragment which had a RecyclerView with Viewpager (using FragmentStatePagerAdapter). It worked well until I switched to different fragment on click of a Cell in RecyclerView, and then navigated back using Phone's hardware Back button and App crashed.

And what's funny about this was that I had two Viewpagers in same RecyclerView and both were about 5 cells away(other wasn't visible on screen, it was down). So initially I just applied the Solution to the first Viewpager and left other one as it is (Viewpager using Fragments).

Navigating back worked fine, when first view pager was viewable . Now when i scrolled down to the second one and then changed fragment and came back , it crashed (Same thing happened with the first one). So I had to change both the Viewpagers.

Anyway, read below to find working solution.

Crash Error below:

java.lang.IllegalArgumentException: No view found for id 0x7f0c0098 (com.kk:id/pagerDetailAndTips) for fragment ProductDetailsAndTipsFragment{189bcbce #0 id=0x7f0c0098}

Spent hours debugging it. Read this complete Thread post till the bottom applying all the solutions including making sure that I am passing childFragmentManager.

Nothing worked.

Finally instead of using FragmentStatePagerAdapter , I extended PagerAdapter and used it in Viewpager without Using fragments. I believe some where there is a BUG with nested fragments. Anyway, we have options. Read ...

Below link was very helpful :

Link may die so I am posting my implemented Solution here below:

public class ScreenSlidePagerAdapter extends PagerAdapter {

private static final String TAG = "ScreenSlidePager";

ProductDetails productDetails;

ImageView imgProductImage;

ArrayList imagelists;

Context mContext;

// Constructor

public ScreenSlidePagerAdapter(Context mContext,ProductDetails productDetails) {

//super(fm);

this.mContext = mContext;

this.productDetails = productDetails;

}

// Here is where you inflate your View and instantiate each View and set their values

@Override

public Object instantiateItem(ViewGroup container, int position) {

LayoutInflater inflater = LayoutInflater.from(mContext);

ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.product_image_slide_cell,container,false);

imgProductImage = (ImageView) layout.findViewById(R.id.imgSlidingProductImage);

String url = null;

if (imagelists != null) {

url = imagelists.get(position).getImage();

}

// This is UniversalImageLoader Image downloader method to download and set Image onto Imageview

ImageLoader.getInstance().displayImage(url, imgProductImage, Kk.options);

// Finally add view to Viewgroup. Same as where we return our fragment in FragmentStatePagerAdapter

container.addView(layout);

return layout;

}

// Write as it is. I don't know much about it

@Override

public void destroyItem(ViewGroup container, int position, Object object) {

container.removeView((View) object);

/*super.destroyItem(container, position, object);*/

}

// Get the count

@Override

public int getCount() {

int size = 0;

if (productDetails != null) {

imagelists = productDetails.getImagelist();

if (imagelists != null) {

size = imagelists.size();

}

}

Log.d(TAG,"Adapter Size = "+size);

return size;

}

// Write as it is. I don't know much about it

@Override

public boolean isViewFromObject(View view, Object object) {

return view == object;

}

}

Hope this was helpful !!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值