android - Bizarre Invalidate behaviour -
i have custom viewgroup (custom2) inside custom viewgroup (custom1).
custom1 has imageview displaying rectshape shapedrawable , 2 textviews.
i set onclicklistener in custom2 removes imageview using this.removeviewat(0) , creates new textureview, calling this.addview (mtextureview, 0) , invalidate. textureview play video using mediaplayer.
here code:
public void settotextureview() { //textureview when not debugging textureview view; view = (textureview) new textureview(mcontext); view.setlayoutparams(new layoutparams(600, 500)); this.removeviewat(0); this.addview(view, 0); view.invalidate(); log.d("debug", "invalidate called"); view.setsurfacetexturelistener(new textureview.surfacetexturelistener() { @override public void onsurfacetextureavailable(surfacetexture surface, int width, int height) { surface msurface = new surface(surface); mediaplayer mmediaplayer = new mediaplayer(); //debug mediaplayer issues setting itemtodebug = "mediaplayer" try { mmediaplayer.setdatasource(mcontext, uri.parse("android.resource://" + mcontext.getpackagename() + "/" + r.raw.t)); if (itemtodebug.equals("mediaplayer")) { log.d("mediaplayer", "data source set"); } mmediaplayer.setsurface(msurface); if (itemtodebug.equals("mediaplayer")) { log.d("mediaplayer", "surface set"); } mmediaplayer.prepare(); if (itemtodebug.equals("mediaplayer")) { log.d("mediaplayer", "prepared"); } } catch (ioexception e) { log.d("ioexception", e.getmessage()); } mmediaplayer.setonpreparedlistener(new mediaplayer.onpreparedlistener() { @override public void onprepared(mediaplayer mp) { if (itemtodebug.equals("mediaplayer")) { log.d("debug", "media player prepared"); } mp.start(); } }); }
now, notice bizarrely imageview disappears , empty space appears (of correct size) when click view, no video plays, although code appears execute fine upto invalidate();
however, can textureview surfacetexture , play video when interrupt program , go in (i.e pressing button takes screen open programs, , selecting activity again.)
i don't have understanding of happening pretty sure no surfacetexture being created because onattached() isn't being called.
does know might going on?
cheers,
j
the view disappears, need call requestlayout() in order draw else there.