java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.Gallery$LayoutParams -
i trying add fancycoverflow
in app,it works fine static image given in this example.
but did changes in adapter, , try run app , crashes , shows following error
fatal exception: main java.lang.classcastexception: android.view.viewgroup$layoutparams cannot cast android.widget.gallery$layoutparams @ android.widget.gallery.setupchild(gallery.java:889) @ android.widget.gallery.makeandaddview(gallery.java:858) @ android.widget.gallery.layout(gallery.java:665) @ android.widget.gallery.onlayout(gallery.java:357) @ android.view.view.layout(view.java:14118) @ android.view.viewgroup.layout(viewgroup.java:4467) @ android.widget.linearlayout.setchildframe(linearlayout.java:1670) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1528) @ android.widget.linearlayout.onlayout(linearlayout.java:1441) @ android.view.view.layout(view.java:14118) @ android.view.viewgroup.layout(viewgroup.java:4467) @ android.widget.relativelayout.onlayout(relativelayout.java:1021) @ android.view.view.layout(view.java:14118) @ android.view.viewgroup.layout(viewgroup.java:4467) @ android.widget.relativelayout.onlayout(relativelayout.java:1021) @ android.view.view.layout(view.java:14118) @ android.view.viewgroup.layout(viewgroup.java:4467) @ android.widget.relativelayout.onlayout(relativelayout.java:1021) @ android.view.view.layout(view.java:14118) @ android.view.viewgroup.layout(viewgroup.java:4467) @ android.widget.framelayout.onlayout(framelayout.java:448) @ android.view.view.layout(view.java:14118) @ android.view.viewgroup.layout(viewgroup.java:4467) @ android.widget.linearlayout.setchildframe(linearlayout.java:1670) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1528) @ android.widget.linearlayout.onlayout(linearlayout.java:1441) @ android.view.view.layout(view.java:14118) @ android.view.viewgroup.layout(viewgroup.java:4467) @ android.widget.framelayout.onlayout(framelayout.java:448) @ android.view.view.layout(view.java:14118) @ android.view.viewgroup.layout(viewgroup.java:4467) @ android.view.viewrootimpl.performlayout(viewrootimpl.java:2183) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1947) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1139) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:4872) @ android.view.choreographer$callbackrecord.run(choreographer.java:776) @ android.view.choreographer.docallbacks(choreographer.java:579) @ android.view.choreographer.doframe(choreographer.java:548) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:762) @ android.os.handler.handlecallback(handler.java:800) @ android.os.handler.dispatchmessage(handler.java:100) @ android.os.looper.loop(looper.java:194) @ android.app.activitythread.main(activitythread.java:5371) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:525) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600) @ dalvik.system.nativestart.main(native method)
in example given as
import android.app.activity; import android.content.context; import android.content.intent; import android.net.uri; import android.os.bundle; import android.view.gravity; import android.view.view; import android.view.viewgroup; import android.widget.button; import android.widget.imageview; import android.widget.linearlayout; import android.widget.textview; import at.technikum.mti.fancycoverflow.fancycoverflow; import at.technikum.mti.fancycoverflow.fancycoverflowadapter; import at.technikum.mti.fancycoverflow.samples.r; public class viewgroupexample extends activity { // ============================================================================= // supertype overrides // ============================================================================= @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.setcontentview(r.layout.layout_inflate_example); fancycoverflow fancycoverflow = (fancycoverflow) findviewbyid(r.id.fancycoverflow); fancycoverflow.setadapter(new viewgroupexampleadapter()); } // ============================================================================= // private classes // ============================================================================= private static class viewgroupexampleadapter extends fancycoverflowadapter { // ============================================================================= // private members // ============================================================================= private int[] images = {r.drawable.image1, r.drawable.image2, r.drawable.image3, r.drawable.image4, r.drawable.image5, r.drawable.image6,}; // ============================================================================= // supertype overrides // ============================================================================= @override public int getcount() { return images.length; } @override public integer getitem(int i) { return images[i]; } @override public long getitemid(int i) { return i; } @override public view getcoverflowitem(int i, view reuseableview, viewgroup viewgroup) { customviewgroup customviewgroup = null; if (reuseableview != null) { customviewgroup = (customviewgroup) reuseableview; } else { customviewgroup = new customviewgroup(viewgroup.getcontext()); customviewgroup.setlayoutparams(new fancycoverflow.layoutparams(300, 600)); } customviewgroup.getimageview().setimageresource(this.getitem(i)); customviewgroup.gettextview().settext(string.format("item %d", i)); return customviewgroup; } } private static class customviewgroup extends linearlayout { // ============================================================================= // child views // ============================================================================= private textview textview; private imageview imageview; private button button; // ============================================================================= // constructor // ============================================================================= private customviewgroup(context context) { super(context); this.setorientation(vertical); this.textview = new textview(context); this.imageview = new imageview(context); this.button = new button(context); linearlayout.layoutparams layoutparams = new layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent); this.textview.setlayoutparams(layoutparams); this.imageview.setlayoutparams(layoutparams); this.button.setlayoutparams(layoutparams); this.textview.setgravity(gravity.center); this.imageview.setscaletype(imageview.scaletype.center_inside); this.imageview.setadjustviewbounds(true); this.button.settext("goto github"); this.button.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { intent = new intent(intent.action_view, uri.parse("https://davidschreiber.github.com/fancycoverflow")); view.getcontext().startactivity(i); } }); this.addview(this.textview); this.addview(this.imageview); this.addview(this.button); } // ============================================================================= // getters // ============================================================================= private textview gettextview() { return textview; } private imageview getimageview() { return imageview; } } }
and change per requirement is
myadapter
private static class viewgroupexampleadapter extends fancycoverflowadapter { private layoutinflater inflater; public activity a; view vi; public arraylist<hashmap<string, string>> arr; public arraylist<hashmap<string, string>> data; public viewgroupexampleadapter(activity homeactivity, arraylist<hashmap<string, string>> mylist) { arr = mylist; = homeactivity; inflater = (layoutinflater) a.getsystemservice(context.layout_inflater_service); } // ============================================================================= // private members // ============================================================================= // private int[] images = {r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher,}; // ============================================================================= // supertype overrides // ============================================================================= @override public int getcount() { return arr.size(); } @override public object getitem(int position) { // todo auto-generated method stub return position; } @override public long getitemid(int position) { // todo auto-generated method stub system.out.println("position=" + position); return position; } @override public view getcoverflowitem(int i, view reuseableview, viewgroup viewgroup) { view vi = reuseableview; if (vi == null) vi = inflater.inflate(r.layout.create_club_inflate, null); textview date1 = (textview) vi.findviewbyid(r.id.txtdate1); textview date = (textview) vi.findviewbyid(r.id.txtdate); textview team1_name = (textview) vi.findviewbyid(r.id.txtteamname); textview team2_name = (textview) vi.findviewbyid(r.id.txtvanue); textview ground = (textview) vi.findviewbyid(r.id.txt_time); hashmap<string, string> product = new hashmap<string, string>(); product = arr.get(i); system.out.println("name 1= " + product.get("str_team1_name") + " team 2=" + product.get("str_team2_obj_name")); date1.settext(product.get("str_srs")); date.settext(product.get("str_startdt")); team1_name.settext(product.get("str_team1_name")); team1_name.setalpha(5000); team2_name.settext(product.get("str_team2_obj_name")); team2_name.setalpha(5000); // typeface font = typeface.createfromasset(getassets(), "titilliumtext22l006.otf"); int[] color = { color.rgb(100, 100, 100), color.rgb(255, 255, 255) }; float[] color_position = { 0, 1 }; tilemode tile_mode = tilemode.mirror; // or tilemode.repeat; lineargradient lin_grad = new lineargradient(0, 0, 0, 50, color, color_position, tile_mode); shader shader_gradient = lin_grad; team1_name.getpaint().setshader(shader_gradient); team2_name.getpaint().setshader(shader_gradient); //team1_name.settypeface(font); // team2_name.settypeface(font); ground.settext(product.get("str_grnd")); product.get("str_sname"); product.get("str_team2_obj_sname"); string first_team_id = product.get("str__team1_id"); string second_team_id = product.get("str_team2_obj_id"); switch (first_team_id) { case "pak": team1_name.setbackgroundresource(r.drawable.pak); break; case "uae": team1_name.setbackgroundresource(r.drawable.uae); break; case "aus": team1_name.setbackgroundresource(r.drawable.aus); break; case "afg": team1_name.setbackgroundresource(r.drawable.afg); break; case "6": team1_name.setbackgroundresource(r.drawable.ban); break; case "23": team1_name.setbackgroundresource(r.drawable.sco); break; case "2": team1_name.setbackgroundresource(r.drawable.ind); break; case "wi": team1_name.setbackgroundresource(r.drawable.wi); break; case "13": team1_name.setbackgroundresource(r.drawable.nz); break; case "sl": team1_name.setbackgroundresource(r.drawable.sl); break; case "9": team1_name.setbackgroundresource(r.drawable.eng); break; case "27": team1_name.setbackgroundresource(r.drawable.ir); break; case "11": team1_name.setbackgroundresource(r.drawable.rsa); break; case "zim": team1_name.setbackgroundresource(r.drawable.zim); break; case "63": team1_name.setbackgroundresource(r.drawable.kol_fl); break; case "62": team1_name.setbackgroundresource(r.drawable.mum_fl); break; case "58": team1_name.setbackgroundresource(r.drawable.chn_fl); break; case "61": team1_name.setbackgroundresource(r.drawable.del_fl); break; case "65": team1_name.setbackgroundresource(r.drawable.pun_fl); break; case "64": team1_name.setbackgroundresource(r.drawable.raj_fl); break; case "255": team1_name.setbackgroundresource(r.drawable.hyd_fl); break; case "59": team1_name.setbackgroundresource(r.drawable.blr_fl); break; default: team1_name.setbackgroundresource(r.drawable.otherflag); // h_upcoming.tv_left.settext(str1); break; } // second team switch (second_team_id) { case "pak": team2_name.setbackgroundresource(r.drawable.pak); break; case "uae": team2_name.setbackgroundresource(r.drawable.uae); break; case "aus": team2_name.setbackgroundresource(r.drawable.aus); break; case "afg": team2_name.setbackgroundresource(r.drawable.afg); break; case "6": team2_name.setbackgroundresource(r.drawable.ban); break; case "23": team2_name.setbackgroundresource(r.drawable.sco); break; case "2": team2_name.setbackgroundresource(r.drawable.ind); break; case "wi": team2_name.setbackgroundresource(r.drawable.wi); break; case "13": team2_name.setbackgroundresource(r.drawable.nz); break; case "sl": team2_name.setbackgroundresource(r.drawable.sl); break; case "9": team2_name.setbackgroundresource(r.drawable.eng); break; case "27": team2_name.setbackgroundresource(r.drawable.ir); break; case "11": team2_name.setbackgroundresource(r.drawable.rsa); break; case "zim": team2_name.setbackgroundresource(r.drawable.zim); break; case "63": team2_name.setbackgroundresource(r.drawable.kol_fl); break; case "62": team2_name.setbackgroundresource(r.drawable.mum_fl); break; case "58": team2_name.setbackgroundresource(r.drawable.chn_fl); break; case "61": team2_name.setbackgroundresource(r.drawable.del_fl); break; case "65": team2_name.setbackgroundresource(r.drawable.pun_fl); break; case "64": team2_name.setbackgroundresource(r.drawable.raj_fl); break; case "255": team2_name.setbackgroundresource(r.drawable.hyd_fl); break; case "59": team2_name.setbackgroundresource(r.drawable.blr_fl); break; default: team1_name.setbackgroundresource(r.drawable.otherflag); // h_upcoming.tv_left.settext(str1); break; } return vi; } } /* private static class customviewgroup extends linearlayout { // ============================================================================= // child views // ============================================================================= private textview textview; private imageview imageview; private button button; // ============================================================================= // constructor // ============================================================================= private customviewgroup(context context) { super(context); this.setorientation(vertical); this.textview = new textview(context); this.imageview = new imageview(context); this.button = new button(context); linearlayout.layoutparams layoutparams = new layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent); this.textview.setlayoutparams(layoutparams); this.imageview.setlayoutparams(layoutparams); this.button.setlayoutparams(layoutparams); this.textview.setgravity(gravity.center); this.imageview.setscaletype(imageview.scaletype.center_inside); this.imageview.setadjustviewbounds(true); this.button.settext("goto github"); this.button.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { intent = new intent(intent.action_view, uri.parse("https://davidschreiber.github.com/fancycoverflow")); view.getcontext().startactivity(i); } }); this.addview(this.textview); this.addview(this.imageview); this.addview(this.button); } // ============================================================================= // getters // ============================================================================= private textview gettextview() { return textview; } private imageview getimageview() { return imageview; } }*/
find import android.view.viewgroup.layoutparams;
line , replace import android.widget.linearlayout.layoutparams;
line
Comments
Post a Comment