Monday, 15 June 2015

android - ViewPager as listview row java.lang.IllegalArgumentException: No view found for id -



android - ViewPager as listview row java.lang.IllegalArgumentException: No view found for id -

i trying set viwepager row in listview. works , can scroll horisontaly , vertically.

after scrolling getting java.lang.illegalargumentexception: no view found id.... below cod , error log.

my adapter

private class expadapter extends cursoradapter { public expadapter(context context, fragmentmanager mfragmentmanager) { super(context, null, 0); this.mfragmentmanager = mfragmentmanager; minflater = layoutinflater.from(context); } private fragmentmanager mfragmentmanager; layoutinflater minflater; private date d = new date(); @override public view newview( context context, cursor cursor, viewgroup parent ) { viewpager pager = (viewpager) minflater.inflate( r.layout.view_pager, parent, false ); pager.setid(r.id.viewpager_id_base + cursor.getposition()); homecoming pager; } @override public void bindview( view view, context context, cursor cursor ) { // create pagercoursor screenslidepageradapter tempmyfriendpageradapter = new screenslidepageradapter( mfragmentmanager, pagercoursor ); ((viewpager) view).setadapter(tempmyfriendpageradapter); } }

xml

<android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="400dip"/>

error

java.lang.illegalargumentexception: no view found id 0x7f070000 (com.yarh.bigdig.smsgreeter:id/viewpager_id_base) fragment screenslidepagefragment{41cfea70 #1 id=0x7f070000} @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:939) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1126) @ android.support.v4.app.backstackrecord.run(backstackrecord.java:739) @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1489) @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:486) @ android.support.v4.app.fragmentstatepageradapter.finishupdate(fragmentstatepageradapter.java:163) @ android.support.v4.view.viewpager.populate(viewpager.java:1073) @ android.support.v4.view.viewpager.populate(viewpager.java:919) @ android.support.v4.view.viewpager.setadapter(viewpager.java:447) @ com.yarh.bigdig.smsgreeter.ui.celebrationlistfragment$expadapter.bindview(celebrationlistfragment.java:367) @ android.support.v4.widget.cursoradapter.getview(cursoradapter.java:256) @ android.widget.abslistview.obtainview(abslistview.java:2435) @ android.widget.listview.makeandaddview(listview.java:1891) @ android.widget.listview.filldown(listview.java:792) @ android.widget.listview.fillgap(listview.java:756) @ android.widget.abslistview.trackmotionscroll(abslistview.java:5718) @ android.widget.abslistview$flingrunnable.run(abslistview.java:4816) @ android.view.choreographer$callbackrecord.run(choreographer.java:799) @ android.view.choreographer.docallbacks(choreographer.java:599) @ android.view.choreographer.doframe(choreographer.java:558) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:784) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:157) @ android.app.activitythread.main(activitythread.java:5872) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:858) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:674) @ dalvik.system.nativestart.main(native method)

i assumed eror caused id clashes, tried replace

pager.setid(r.id.viewpager_id_base + cursor.getposition());

with

if (build.version.sdk_int < build.version_codes.jelly_bean_mr1) { myview.setid(utils.generateviewid()); } else { myview.setid(view.generateviewid()); }

as suggested here, show me immidiate resourcenofound exeption

the key me was, clear childs of linear layout , set new viewpager every time adapter phone call getview

@override public void bindview( view view, context context, cursor cursor ) { final string date = cursor.getstring(1); string[] projection = {celebrationtable.table_celebration + "." + celebrationtable.column_id }; string selection = " , strftime(" + datelimiter + ", " + celebrationtable.table_celebration + "." + celebrationtable.column_date + " / 1000, 'unixepoch') = '" + date + "'"; string orderby = celebrationtable.table_celebration + "." + celebrationtable.column_date + " asc"; cursor pagercoursor = context.getcontentresolver() .query( celebrationcontentprovider.content_uri, projection, selection, null, orderby ); viewpager pager = new viewpager(minflater.getcontext()); pager.setlayoutparams( new viewgroup.layoutparams( viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent ) ); viewholder holder = (viewholder) view.gettag(); holder.ll.removeallviews(); holder.ll.addview(pager); pager.setid(idarrays[cursor.getposition()]); int curpos = cursor.getposition(); arraylist<long> celebrationids = new arraylist<>(); while (pagercoursor.movetonext()){ celebrationids.add(pagercoursor.getlong(0)); } screenslidepageradapter tempmyfriendpageradapter = new screenslidepageradapter( mfragmentmanager, celebrationids, curpos ); pagercoursor.close(); pager.setadapter(tempmyfriendpageradapter); }

android listview

No comments:

Post a Comment