android


How onClick image with gridLayout to different Activity


This is my image:
If I need to try anything please advice me.
My code fragment:
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;
}
my adapter
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);
}
}
and this my error
05-13 11:45:54.091 8712-8712/com.example.androiddev.army31 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.androiddev.army31, PID: 8712
java.lang.RuntimeException: Parcel: unable to marshal value com.example.androiddev.army31.Shop#778fcae
at android.os.Parcel.writeValue(Parcel.java:1476)
at android.os.Parcel.writeList(Parcel.java:811)
at android.os.Parcel.writeValue(Parcel.java:1423)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:723)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1412)
at android.os.Bundle.writeToParcel(Bundle.java:1133)
at android.os.Parcel.writeBundle(Parcel.java:763)
at android.content.Intent.writeToParcel(Intent.java:8788)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3071)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1539)
at android.app.Activity.startActivityForResult(Activity.java:4391)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4335)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4697)
at android.app.Activity.startActivity(Activity.java:4665)
at com.example.androiddev.army31.ShopRecycleAdaptor$1.onClick(ShopRecycleAdaptor.java:57)
at android.view.View.performClick(View.java:5646)
at android.view.View$PerformClick.run(View.java:22458)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
Is Shop class Parcelable? To put any custom class into a Bundle the class must implement the Parcelable interface. See here.
https://developer.android.com/reference/android/os/Parcelable.html
Your stack trace error suggests that the info being added is not in fact Parcelable compliant, so it's not the onClick error that's causing the issue its the
intent.putExtra("shop", shop);
line if I am reading this correctly.

Related Links

Is there an autocomplete api for google playstore?
Any things like jQuery parseJSON in Android?
Full Screen Video Without Break Aspect Ratio
Get insert error code on sqlite
How can I get the View in the FileTransfer upload method in PhoneGap?
In Android, how can I play mp3 through telephony and not allow to play through wired headset or bluetooth headset even if it is plugged in?
Difficulty in updating a contact in SQLite
android socket nullPointerExeption
Spinner with custom adapter doesn't disappear on selection
Is there always one instance of Billing Service on Android?
ABBYY recognizing bussiness card work but photo fails
Android Simulate Roaming
How to set listview scroll one item by one item [closed]
Exception while parsing the url
ANDROID - positioning views programatically
About Android SDK add-on development

Categories

HOME
cheerio
oracle-apex-5
nsbundle
aws-cli
opengl-3
nfs
extjs4.2
qpython
openpyxl
resultset
symmetricds
android-7.0-nougat
easyphp
google-content-api
backpack-for-laravel
syntax-highlighting
gpio
fable-f#
jackson-modules
comparable
postback
record
database-comparison
papaparse
arduino-ide
raft
openerp-7
alphabetical
openalpr
reactivekit
xdocreport
android-augmented-reality
projects-and-solutions
chef-solo
apriori
attributeerror
microsoft-metro
glm-math
apollostack
http-request
chai-as-promised
android-testing
java-websocket
objectscript
smartfoxserver
cubism.js
file-uri
neon
jodd
model-associations
x-tag
android-dateutils
stream-processing
html-to-pdf
aspen
np-spring
kendo-upload
cycle2
iokit
include-guards
slash
finalbuilder
ms-access-2000
openbabel
rapidsvn
nodelist
contrast
human-computer-interface
build-script
matrix-inverse
malformedurlexception
maven-scm
sbcl
android-audiorecord
gwt-openlayers
notorm
cffile
composite-component
chart-director
wimax
midlet
cakephp-1.2
zope.interface
subgraph
garbage
google-maps-mobile
xui
http-daemon
squishit
non-clustered-index
binomial-heap
silverlight-oob
dsl-tools
movieplayer
change-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App