へのGridLayoutとのonClick画像は、これは私のイメージである方法:私は何をしようとする必要がある場合はは異なる活動
私にアドバイスをしてください。
私のコードフラグメント:
public class ShopFragment extends Fragment {
private int imgShop[] = {R.drawable.thumbnail_01,
R.drawable.thumbnail_02,
R.drawable.thumbnail_03,
R.drawable.thumbnail_04,
R.drawable.thumbnail_05,
R.drawable.thumbnail_06};
ViewPager pager;
SearchView searchView;
private int img[] = {R.drawable.scroll_view, R.drawable.scroll_view, R.drawable.scroll_view, R.drawable.scroll_view};
public ShopFragment() {
// Required empty public constructor
}
private ArrayList<Shop> prepareShop() {
ArrayList<Shop> shop = new ArrayList<>();
for (int i = 0; i < imgShop.length; i++) {
Shop shops = new Shop();
shops.setShop_img(imgShop[i]);
shop.add(shops);
}
return shop;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_shop, container, false);
pager = (ViewPager) view.findViewById(R.id.img_pager);
ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getContext(), img);
pager.setAdapter(viewPagerAdapter);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.mRecyclerShop);
RecyclerView.LayoutManager layoutmanager = new GridLayoutManager(getContext(), 3);
recyclerView.setLayoutManager(layoutmanager);
ArrayList<Shop> shops = prepareShop();
ShopRecycleAdaptor adaptor = new ShopRecycleAdaptor(getContext(), shops);
recyclerView.setAdapter(adaptor);
return view;
}
私のアダプタ
public class ShopRecycleAdaptor extends RecyclerView.Adapter<ShopRecycleAdaptor.ViewHolder> {
private ArrayList<Shop> shop;
private Context context;
private int[] imgShop;
public ShopRecycleAdaptor(Context context, ArrayList<Shop> shop) {
this.shop = shop;
this.context = context;
}
@Override
public ShopRecycleAdaptor.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.model_shop, viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ShopRecycleAdaptor.ViewHolder holder, int position) {
Picasso.with(context)
.load(shop.get(position)
.getShop_img())
.into(holder.imgShop);
holder.imgShop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), ShopType.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("shop", shop);
v.getContext().startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return shop.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private ImageView imgShop;
public ViewHolder(View view) {
super(view);
imgShop = (ImageView) view.findViewById(R.id.img_shop);
}
}
と、この私のエラー
5月13日11:45:54.091 8712から8712/com.example。 androiddev.army31 E/AndroidRuntime:致命的除外:メイン プロセス:com.example.androiddev.army31、PID:8712 java.lang.RuntimeException:パーセル:値をマーシャリングできません[email protected] android.os.Parcel.writeValue(Parcel.java:1476) android.os.Parcel.writeList( (Parcel.java:811) (android.os.Parcel.writeValue(Parcel.java:1423)) (android.os.Parcel.writeArrayMapInternal(Parcel.java:723)) at android.os.BaseBundle.writeToParcelInner(BaseBundle。 java:1412) android.os.Bundle.writeToParcel(Bundle.java:1133) (android.os.Parcel.writeBundle(Parcel.java:763)) at android.content.Intent.writeToParcel(Intent.java: 8788)android.app.Activity.startActivityForResultでandroid.app.Instrumentation.execStartActivity(Instrumentation.java:1539) でandroid.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3071) (Activity.java:4391) でで(アクティビティ)。アクティビティjava:4335)and35.png tivity.startActivity(Activity.java:4697) android.app.Activity.startActivity(Activity.java:4665) at com.example.androiddev.army31.ShopRecycleAdaptor $ 1.onClick(ShopRecycleAdaptor.java:57) でandroid .view.View.performClick(View.java:5646) (android.view.View)$ PerformClick.run(View.java:22458) (android.os.Handler.handleCallback(Handler.java:761)) でandroid .os.Handler.dispatchMessage(Handler.java:98)android.os.Looper.loop(Looper.java:156)の とandroid.app.ActivityThread.main(ActivityThread.java:6524) at java.lang .reflect.Met hod.invoke(ネイティブメソッド) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:941) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
ありがとうございました –
@ C.ジュニアおかげさまで、これがうまくいけば答えとして受け入れてください! – Mercato