android - List item is not visible in fragment -
i developing music app. following code of songs list. when run app, music artworks showing. other information album name, duration not showing in listview
.
public class songs_list extends fragment { // adapter exposes data cursor listview widget. private songs_list.mediacursoradapter mediaadapter = null; private string currentfile=""; private boolean isstarted = true; private textview selelctedfile = null; private view v=null; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // use cursor data external resource cursor cursor = getactivity().getcontentresolver().query(mediastore.audio.media.external_content_uri, null, null, null, null); // check cursor has data or not if (null != cursor) { cursor.movetofirst(); mediaadapter = new mediacursoradapter(getactivity().getapplicationcontext(), r.layout.list_layout, cursor); v=inflater.inflate(r.layout.fragment_songs_list, container, false); // textview title = (textview) view.findviewbyid(r.id.title); listview lv = (listview)v.findviewbyid(android.r.id.list); lv.setadapter(mediaadapter); } // inflate layout fragment return v; } mediaplayer player = new mediaplayer(); //mediacursoradapter class construction (what show ) private class mediacursoradapter extends simplecursoradapter { public mediacursoradapter(context context, int layout, cursor c) { super(context, layout, c, new string[]{mediastore.audio.albums.album_id, mediastore.mediacolumns.title, mediastore.extra_media_artist, mediastore.audio.audiocolumns.duration}, new int[]{r.id.icon, r.id.title, r.id.artistname, r.id.duration}); } @requiresapi(api = build.version_codes.m) @override public void bindview(view view, context context, cursor cursor) { textview title = (textview) view.findviewbyid(r.id.title); imageview img = (imageview) view.findviewbyid(r.id.icon); textview name = (textview) view.findviewbyid(r.id.artistname); textview duration = (textview) view.findviewbyid(r.id.duration); // icon long albumid = long.parselong((cursor.getstring(cursor.getcolumnindex(mediastore.audio.albums.album_id)))); uri sartworkuri = uri.parse("content://media/external/audio/albumart"); uri uri = contenturis.withappendedid(sartworkuri, albumid); contentresolver res = context.getcontentresolver(); inputstream in = null; try { in = res.openinputstream(uri); } catch (filenotfoundexception e) { e.printstacktrace(); } bitmap artwork = bitmapfactory.decodestream(in); img.setimagebitmap(artwork); title.settext(cursor.getstring( cursor.getcolumnindex(mediastore.mediacolumns.title))); name.settext(cursor.getstring( cursor.getcolumnindex(mediastore.extra_media_artist))); long durationinms = long.parselong(cursor.getstring( cursor.getcolumnindex(mediastore.audio.audiocolumns.duration))); double durationinmin = ((double) durationinms / 1000.0) / 60.0; durationinmin = new bigdecimal(double.tostring(durationinmin)).setscale(2, bigdecimal.round_up).doublevalue(); duration.settext("" + durationinmin); view.settag(cursor.getstring(cursor.getcolumnindex(mediastore.mediacolumns.data))); } @override public view newview(context context, cursor cursor, viewgroup parent) { layoutinflater inflater = layoutinflater.from(context); view v = inflater.inflate(r.layout.list_layout, parent, false); bindview(v, context, cursor); return v; } } }
in style :
<style name="textcolor"> <item name="android:textcolor">#00ff00</item> </style>
in layout file :
<textview style="@style/textcolor" />
this fix color 1 default want.
Comments
Post a Comment