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

Get nulls in response from server in android
Add google analytics tracker to fragment
Issue In Creating Emulator in Android Studio 2.2.3
How to validate date in android
Android override input method with custom view
Connect elements on android view
Picking an Image File From an External SD Card (USB OTG Storage)
Why do SearchView and android.support.v7.widget.SearchView not focus anymore
RxJava: return a cached value synchronously/immediately
How to check for string changes after a user presses a Button?
android - groovy script error in custom live template
How to zoom in an ImageView in Android
How to load string.xml for indian languages in android?
Classic asp or phonegap
Android WhisperSystems/libsignal-service
android retrofit await method to finish outside of response

Categories

HOME
grok
facebook-oauth
apache-flink
css3
object
flex
mstest
nsbundle
onclick
limit
regular-language
maxscript
jtextpane
joomla3.0
jsonpath
selenium-ide
atlassian
selectize.js
mathprog
forgot-password
html5-appcache
soci
sse
nodemcu
swagger-2.0
sar
springfox
interpreter
jquery-callback
expressionengine3
tiki-wiki
onload
eviews
complex-numbers
jbutton
playstation-portable
rselenium
mailkit
hibernate-search
pdw-file-browser
numpy-broadcasting
raft
sql-server-ce
dm-script
comparison-operators
wmp
uiimage
oim
ntvs
openal
amq
java-websocket
template-toolkit
reporting-services-2012
watch-os-2
mta
jboss-tools
jquery-jscrollpane
jclouds
mediametadataretriever
bizagi
gcloud-ruby
hadoop-partitioning
flock
poppler
rubaxa-sortable
toolkit
sapscript
sony-lifelog-api
finalbuilder
jsvc
linked-tables
graphics2d
beatsmusic
crowd
gii
malformedurlexception
grails-plugin-rabbitmq
winginx
twitter-bootstrap-rails
ora-06550
jeromq
observium
process-explorer
node-blade
cascadingdropdown
robotlegs
josql
apache-whirr
hibernateexception
convention
ikimagebrowserview
listactivity
exponentiation
dataform
undefined-index
silent
burndowncharts
pagemethods
software-lifecycle

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