java - Cursor Adapter behaving strangely (Info in each item is being updated as I scroll, and I can see it being updated) -
okay, not know better way of explaining in words uploaded video, can see going on...
a little background app.. app takes info firebase , stores in sq lite. cursor adapter uses info in sq lite, show items in listview, inside bottom sheet (android design support library)
here cursor adapter code:
public class eventlistcursoradapter extends cursoradapter { private layoutinflater cursorinflater; calculations calculations = new calculations(); gson gson = new gson(); context appcontext; databasehelper dbhelper; context mcontext; string[] whereclause; intent mainactivityintent; public eventlistcursoradapter(context context, cursor c, int flags) { super(context, c, flags); cursorinflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); appcontext = context.getapplicationcontext(); mcontext = context; notifydatasetchanged(); } @override public view newview(context context, cursor cursor, viewgroup parent) { return cursorinflater.inflate(r.layout.card_view, parent, false); } @override public void bindview(view view, context context, cursor cursor) { notifydatasetchanged(); textview timetext = (textview) view.findviewbyid(r.id.event_time); textview nametext = (textview) view.findviewbyid(r.id.event_name); textview datetext = (textview) view.findviewbyid(r.id.event_date); textview summarytext = (textview) view.findviewbyid(r.id.event_summary); textview locationtext = (textview) view.findviewbyid(r.id.event_location); textview categorytext = (textview) view.findviewbyid(r.id.event_category); cardview card = (cardview) view.findviewbyid(r.id.cardviewitem); final cursor mcursor = cursor; string date = calculations.unixtimeconverter( mcursor.getlong(mcursor.getcolumnindex(databasehelper.col_unixtime) ))[0]; string time = calculations.unixtimeconverter( mcursor.getlong(mcursor.getcolumnindex(databasehelper.col_unixtime)) )[1]; final latlng location = gson.fromjson(mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_location)),latlng.class); nametext.settext(mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_name))); log.i("bindview cursor check", "name=" + mcursor.getstring((mcursor.getcolumnindex(databasehelper.col_name)))); datetext.settext(date); timetext.settext(time); summarytext.settext(mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_summary))); locationtext.settext(mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_locationname))); categorytext.settext(mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_category))); locationtext.setonclicklistener(new view.onclicklistener(){ @override public void onclick(view v) { final cameraposition camlocation = cameraposition.builder().target(location).zoom(18).build(); mmap.animatecamera(cameraupdatefactory.newcameraposition(camlocation)); } }); summarytext.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { layoutinflater mlayoutinflator; mlayoutinflator = layoutinflater.from(appcontext); final alertdialog.builder mbuilder = new alertdialog.builder(mcontext); view mview = mlayoutinflator.inflate(r.layout.summarydialog,null); textview textview = mview.findviewbyid(r.id.maintext); textview.settext( mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_summary)) ); textview.setmovementmethod(new scrollingmovementmethod()); mbuilder.setview(mview); final alertdialog dialog = mbuilder.create(); dialog.getwindow().setbackgrounddrawable(new colordrawable(color.transparent)); dialog.show(); } }); final int position = mcursor.getposition(); card.setonlongclicklistener(new view.onlongclicklistener() { @override public boolean onlongclick(view view) { whereclause = new string[] {string.valueof(mcursor.getlong(mcursor.getcolumnindex(databasehelper.col_localid)))}; log.v("where clause:",whereclause[0]); log.v("what clicked",position+""); log.i("event onlongclick", "name=" + mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_name))); layoutinflater mlayoutinflator; mlayoutinflator = layoutinflater.from(appcontext); final alertdialog.builder mbuilder = new alertdialog.builder(mcontext); view mview = mlayoutinflator.inflate(r.layout.canceldelete_editor,null); final textview cancelbutton = (textview) mview.findviewbyid(r.id.cancelaction); final textview deletebutton = (textview) mview.findviewbyid(r.id.deleteentryaction); mbuilder.setview(mview); final alertdialog dialog = mbuilder.create(); dialog.show(); dbhelper = new databasehelper(mcontext); final sqlitedatabase db = dbhelper.getwritabledatabase(); dialog.setondismisslistener(new dialoginterface.ondismisslistener() { @override public void ondismiss(dialoginterface dialoginterface) { log.v("where clause changed:",whereclause[0]); } }); cancelbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { dialog.dismiss(); } }); log.v("item lond clicked",mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_name))); deletebutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { mcursor.movetoposition(position); int tru = db.delete(databasehelper.table_name, databasehelper.col_localid + " = " + mcursor.getint(mcursor.getcolumnindex(databasehelper.col_localid)), null); log.v("deleting item:",mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_name))+""); if(tru == 1){ log.v("delete: ", "successfull!" + mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_name))); }else{ log.v("delete: ", "failed!" + mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_name))); } datasendertoserver datasendertoserver = new datasendertoserver(); datasendertoserver.eraseentry(mcursor.getstring(mcursor.getcolumnindex(databasehelper.col_globalid))); mainactivityintent = new intent(mcontext,mainactivity.class); mcontext.startactivity(mainactivityintent); dialog.dismiss(); mcursor.requery(); } }); return true; } }); } }
here mainactivity layout:
> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:name="com.google.android.gms.maps.supportmapfragment" /> <button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" android:text="eventlist button" android:id="@+id/eventlistbutton" android:layout_above="@+id/bottom_navigation" /> <android.support.design.widget.floatingactionbutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/zoomunpressed" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_margintop="12dp" android:layout_marginleft="12dp" android:id="@+id/zoomout" android:clickable="true" app:backgroundtint="@color/cardbackground2" app:fabsize="normal" app:borderwidth="-120000dp" /> <android.support.design.widget.floatingactionbutton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/zoom2unpressed" android:id="@+id/zoomin" android:clickable="true" app:backgroundtint="@color/cardbackground2" app:fabsize="normal" app:borderwidth="-120000dp" app:layout_anchor="@id/zoomout" android:layout_marginleft="12dp" android:layout_marginright="12dp" android:layout_below="@+id/zoomout" /> <button android:id="@+id/searchbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="search" android:text="search" android:layout_alignbottom="@+id/zoomin" android:layout_alignparentend="true" /> <android.support.design.widget.bottomnavigationview android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" app:itembackground="@color/cardbackground" app:itemicontint="@color/white" app:itemtextcolor="@color/white" app:menu="@menu/bottom_navigation_main" /> </relativelayout> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/bottom_sheet_behavior" android:cliptopadding="true" android:orientation="vertical" android:id="@+id/bottomsheet" > <textview android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/cardbackground" android:gravity="center" android:text="event list" android:textcolor="@color/white" android:textstyle="bold" android:textsize="18sp" /> <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="9" android:background="@color/recyclerview_background" > <listview android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/eventlistview" android:paddingleft="@dimen/recyclerviewhorizontalpadding" android:paddingright="@dimen/recyclerviewhorizontalpadding" > </listview> </linearlayout> </linearlayout> </android.support.design.widget.coordinatorlayout>
here each card item xml(do not know if help):
<android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/cardviewitem" android:layout_width="fill_parent" android:layout_height="wrap_content" card_view:cardelevation="8dp" card_view:cardbackgroundcolor="@android:color/transparent" card_view:cardusecompatpadding="true" > <!--android:layout_margintop="8dp"--> <framelayout android:background="@drawable/event_edittext2" android:layout_width="match_parent" android:layout_height="match_parent" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/cardbackground" android:orientation="horizontal" > <textview android:id="@+id/event_name" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:padding="@dimen/cardmargin" android:textcolor="@color/white" android:textsize="18sp" android:textstyle="bold" tools:text="dick museum tour" /> <textview android:id="@+id/event_date" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:padding="@dimen/cardmargin" android:textalignment="viewend" android:textcolor="@color/white" android:textsize="18dp" android:textstyle="bold" tools:text="8/24" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" android:padding="12dp" > <textview android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center_vertical" android:paddingleft="@dimen/cardmargin" android:textcolor="@color/white" android:textsize="18sp" android:text="time:" android:textstyle="bold" /> <textview android:id="@+id/event_time" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginright="18dp" android:layout_weight="3" android:gravity="center_vertical" android:paddingleft="@dimen/cardmargin" android:textalignment="textend" android:textcolor="@color/white" android:textsize="18sp" tools:text="11:50" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" android:padding="12dp" > <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:clickable="true" android:gravity="center_vertical" android:paddingleft="@dimen/cardmargin" android:textcolor="@color/white" android:textsize="18sp" android:text="summary:" android:textstyle="bold" /> <textview android:id="@+id/event_summary" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:clickable="true" android:ellipsize="end" android:gravity="center_vertical" android:maxlength="130" android:maxlines="1" android:paddingleft="@dimen/cardmargin" android:layout_marginright="18dp" android:text="once upon time few missadfsafasdfasfdf" android:textcolor="@color/white" android:textsize="18sp" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" android:padding="12dp" > <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:clickable="true" android:gravity="center_vertical" android:paddingleft="@dimen/cardmargin" android:textcolor="@color/white" android:textsize="18sp" android:text="location:" android:textstyle="bold" /> <textview android:id="@+id/event_location" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:clickable="true" android:gravity="center_vertical" android:paddingleft="@dimen/cardmargin" android:layout_marginright="18dp" android:text="rio de janeiro" android:textalignment="viewend" android:textcolor="@color/white" android:textsize="18sp" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" android:padding="12dp" > <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:clickable="true" android:gravity="center_vertical" android:paddingleft="@dimen/cardmargin" android:textcolor="@color/white" android:textsize="18sp" android:text="category:" android:textstyle="bold" /> <textview android:id="@+id/event_category" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:clickable="true" android:gravity="center_vertical" android:paddingleft="@dimen/cardmargin" android:layout_marginright="18dp" android:text="individual" android:textalignment="viewend" android:textcolor="@color/white" android:textsize="18sp" /> </linearlayout> </linearlayout> </linearlayout> </framelayout> </android.support.v7.widget.cardview>
Comments
Post a Comment