android - passing all array items using a for loop -
android - passing all array items using a for loop -
am trying pass array items can displayed image views facing difficulty in implementing it. help.
class sampledata.java
public static arraylist<data> generatesampledata() { int sampledata[] = { r.drawable.imageone, r.drawable.imagetwo, r.drawable.imagethree }; string repeat = " repeat"; final arraylist<data> datas = new arraylist<data>(); (int = 0; < sample_data_item_count; i++) { info data = new data(); data.image = sampledata[0]; data.title = "pinterest card"; data.description = "super awesome description"; random ran = new random(); int x = ran.nextint(i + sample_data_item_count); (int j = 0; j < x; j++) data.description += repeat; datas.add(data); } homecoming datas;
class data.java
public class info { public int image; public string title; public string description; public data() {} }
here error getting if alter data.image = sampledata[0] data.image = sampledata[i]
06-19 11:51:02.814 1626-1626/com.richapps.true_gamer e/androidruntime﹕ fatal exception: main java.lang.arrayindexoutofboundsexception: length=2; index=2 @ com.richapps.true_gamer.grid.sampledata.generatesampledata(sampledata.java:21) @ com.richapps.true_gamer.findpeoplefragment.oncreateview(findpeoplefragment.java:29) @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:828) @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1032) @ android.app.backstackrecord.run(backstackrecord.java:622) @ android.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1382) @ android.app.fragmentmanagerimpl$1.run(fragmentmanager.java:426) @ android.os.handler.handlecallback(handler.java:605) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4424) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) @ dalvik.system.nativestart.main(native method)
change
data.image = sampledata[0];
to
data.image = sampledata[i];
android
Comments
Post a Comment