我一个活动和两个片段,**片段1和Fragment2。 Fragment1包含ViewPager它在每个页面上都有一个GridView。我想要替换片段1由片段2 onClick的GridView项目,但给出以下错误。移动到新的片段从ViewPager内容
java.lang.IllegalArgumentException: No view found for id 0x7f0d0078 (atrtrendy.nxg.com.atrtrendy:id/container_main) for fragment Fragment_ViewProduct{425b2ec0 #2 id=0x7f0d0078}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5052)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
我在做什么如下:
private class ProductGridAdapter extends BaseAdapter
{
Context context;
ArrayList<Product> productArrayList;
String url = "http://ecom.nxglabs.in/uploads/productImages/";
public ProductGridAdapter(FragmentActivity activity, ArrayList<Product> productArrayList) {
this.context = activity;
this.productArrayList = productArrayList;
}
@Override
public int getCount() {
return productArrayList.size();
}
@Override
public Object getItem(int position) {
return productArrayList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
String strView = preferences.getString("View","Grid");
if(strView.equals("Layout"))
{
convertView = inflater.inflate(R.layout.product_view_layout_item, null);
}else {
convertView = inflater.inflate(R.layout.product_view_item, null);
}
ImageView productImg = (ImageView) convertView.findViewById(R.id.productImg);
TextView productTitle = (TextView) convertView.findViewById(R.id.productTitle);
TextView productBrand = (TextView) convertView.findViewById(R.id.productBrand);
Product product = productArrayList.get(position);
productTitle.setText(product.getProductName());
productBrand.setText(product.getBrandName());
Glide.with(getActivity()).load(url + product.getProductImage()).into(productImg);
productImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment_ViewProduct viewProduct = new Fragment_ViewProduct();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("ProductList", productArrayList);
bundle.putInt("Position", position);
viewProduct.setArguments(bundle);
getFragmentManager().beginTransaction().replace(R.id.container_main, viewProduct).commit();
}
});
return convertView;
}
}
这是Fragment_ViewProduct的问题,Fragment_ViewProduct的后代码 – raj