android - Renamed file does not shows up in RecyclerView, crashes the app instead -
i using recyclerview first time, trying rename file in view. file gets renamed recycler not updates itself. implemented mediascanner crashes app, after restart list gets updated renamed file. there way update list without calling media scanner?
specific renaming code:
holder.renamebutton.setonclicklistener(new view.onclicklistener(){ @override public void onclick(view v) { alertdialog.builder builder = new alertdialog.builder(mcontext); builder.settitle("title"); // set input final edittext input = new edittext(mcontext); // specify type of input expected; this, example, sets input password, , mask text input.setinputtype(inputtype.type_class_text ); builder.setview(input); // set buttons builder.setpositivebutton("ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { m_text = input.gettext().tostring(); file mydir =new file( environment.getexternalstoragedirectory()+"/freesoundrecorder/"); if(mydir.exists()){ file = new file(mydir,music.gettitle()+".mp3"); file = new file(mydir,m_text+".mp3"); if(from.exists()) { from.renameto(to); string filepath=environment.getexternalstoragedirectory().getabsolutepath()+"/freesoundrecorder/"+ m_text+".mp3"; mediascannerconnection.scanfile( mcontext, new string[]{filepath}, null, new mediascannerconnection.onscancompletedlistener() { @override public void onscancompleted(string path, uri uri) { log.v("mehnatsafal", "file " + path + " scanned seccessfully: " + uri); } }); mcontext.getcontentresolver().delete(trackuri, null,null); notifyitemremoved(position); notifyitemrangechanged(position,mmusic.size()); } } } }); builder.setnegativebutton("cancel", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { dialog.cancel(); } }); builder.show(); }
logcat:
09-13 14:33:49.270 16453-16453/cafe.adriel.androidaudiorecorder.example e/androidruntime: fatal exception: main process: cafe.adriel.androidaudiorecorder.example, pid: 16453 java.lang.indexoutofboundsexception: inconsistency detected. invalid view holder adapter positionviewholder{42450820 position=7 id=-1, oldpos=1, plpos:1 scrap [attachedscrap] tmpdetached no parent} @ android.support.v7.widget.recyclerview$recycler.validateviewholderforoffsetposition(recyclerview.java:4251) @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:4382) @ android.support.v7.widget.recyclerview$recycler.getviewforposition(recyclerview.java:4363) @ android.support.v7.widget.linearlayoutmanager$layoutstate.next(linearlayoutmanager.java:1961) @ android.support.v7.widget.linearlayoutmanager.layoutchunk(linearlayoutmanager.java:1370) @ android.support.v7.widget.linearlayoutmanager.fill(linearlayoutmanager.java:1333) @ android.support.v7.widget.linearlayoutmanager.onlayoutchildren(linearlayoutmanager.java:562) @ android.support.v7.widget.recyclerview.dispatchlayout(recyclerview.java:2864) @ android.support.v7.widget.recyclerview.onlayout(recyclerview.java:3071) @ android.view.view.layout(view.java:14828) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.linearlayout.setchildframe(linearlayout.java:1671) @ android.widget.linearlayout.layouthorizontal(linearlayout.java:1660) @ android.widget.linearlayout.onlayout(linearlayout.java:1436) @ android.view.view.layout(view.java:14828) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.framelayout.layoutchildren(framelayout.java:453) @ android.widget.framelayout.onlayout(framelayout.java:388) @ android.view.view.layout(view.java:14828) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.support.v7.widget.actionbaroverlaylayout.onlayout(actionbaroverlaylayout.java:435) @ android.view.view.layout(view.java:14828) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.framelayout.layoutchildren(framelayout.java:453) @ android.widget.framelayout.onlayout(framelayout.java:388) @ android.view.view.layout(view.java:14828) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.linearlayout.setchildframe(linearlayout.java:1671) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1525) @ android.widget.linearlayout.onlayout(linearlayout.java:1434) @ android.view.view.layout(view.java:14828) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.widget.framelayout.layoutchildren(framelayout.java:453) @ android.widget.framelayout.onlayout(framelayout.java:388) @ android.view.view.layout(view.java:14828) @ android.view.viewgroup.layout(viewgroup.java:4631) @ android.view.viewrootimpl.performlayout(viewrootimpl.java:2033) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1790) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1046) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5655) @ android.view.choreographer$callbackrecord.run(choreographer.java:761) @ android.view.choreographer.docallbacks(choreographer.java:574) @ android.view.choreographer.doframe(choreographer.java:544) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:747) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5052) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:796) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:612) @ dalvik.system.nativestart.main(native method)
so possible solution this? in advance.
Comments
Post a Comment