I have ListView
and i uses ion library to load images in he rows
of it, When i tap on any row
i take the data on the row
like TextView
and display it in activity using Intent
// Keys
public static String TITLE = "title";
public static String ARTICLE = "article";
public static String IMG = "img";
Intent passData = new Intent(getContext(), ArticleScreen.class);
passData.putExtra(TITLE, tv.getText());
passData.putExtra(ARTICLE, tv2.getText());
getContext().startActivity(passData);
Bundle extras = getIntent().getExtras();
if (extras != null) {
title = extras.getString(NewsAdapter.TITLE);
article = extras.getString(NewsAdapter.ARTICLE);
}
Now I have different ImageView
in every row
in the ListView
and i want to display that image in the activity with the text using ion library, So i have Array
of String
named thumbUrl
contains the urls
that i want to display in the row
and activity
.
ImageView iv = (ImageView) v.findViewById(R.id.mThumb);
Ion.with(getContext()).load(thumbUrl[position])
.withBitmap()
.placeholder(R.drawable.ic_settings_black_24dp)
.error(R.drawable.ic_info_outline_black_24dp)
.intoImageView(iv);
So i tried to send that thumbUrl
Array
using Bundle
and Intent
like this:
Bundle b = new Bundle();
b.putStringArray(IMG, thumbUrl);
Intent passData = new Intent(getContext(), ArticleScreen.class);
passData.putExtra(TITLE, tv.getText());
passData.putExtra(ARTICLE, tv2.getText());
passData.putExtras(b);
getContext().startActivity(passData);
and receive it like this:
private String[] img;
Bundle extras = getIntent().getExtras();
if (extras != null) {
title = extras.getString(NewsAdapter.TITLE);
article = extras.getString(NewsAdapter.ARTICLE);
img = extras.getStringArray(NewsAdapter.IMG);
}
ImageView iv = (ImageView) findViewById(R.id.articleImg);
Ion.with(this).load(Arrays.toString(img))
.withBitmap()
.placeholder(R.drawable.ic_settings_black_24dp)
.error(R.drawable.ic_info_outline_black_24dp)
.intoImageView(iv);
But it's gives me that exception
08-20 23:51:23.841 28725-28725/com.mEmoZz.App W/Bundle﹕ Key img expected String[] but value was a java.lang.Integer. The default value <null> was returned.
08-20 23:51:23.843 28725-28725/com.mEmoZz.App W/Bundle﹕ Attempt to cast generated internal exception:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String[]
at android.os.BaseBundle.getStringArray(BaseBundle.java:1258)
at com.mEmoZz.App.ArticleScreen.onCreate(ArticleScreen.java:36)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5291)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
So what to do right now?
Sorry for that messy problem but am just a beginner and that's my first time to deal with apps like that.
You should pass the url of the image related to the row being clicked. DO NOT pass the whole array:
//In the Sender:
passData.putExtra(IMG, thumbUrl[position]);
//In the Receiver
String img = extras.getString(NewsAdapter.IMG);