Android - ListView displaying different layouts for items -


i'm having listview displays list of items database. using simplecursoradapter.

if (mdiscussionscursor != null && mdiscussionscursor.getcount() > 0) {     madapter = new simplecursoradapter(mcontext, r.layout.home_discussion_row, mdiscussionscursor, from, to, 0);     madapter.setviewbinder(view_binder);     setadapter(madapter);     setonitemclicklistener(this); } 

these items chronologically ordered. put separation line between every day, i.e., display items may 1, 2013, title 'may 2, 2013' followed items of day etc.

i assume can take cursor , copy array special cells representing titles days , use method presented here: http://android.amberfog.com/?p=296

however, seems wasteful practice me in both space , time, , wondering maybe can think of more clever. in advance.

you can try sub-classing simplecursoradapter , overriding associated members tutorial

getitemviewtype getviewtypecount getview 

if have @ inheritance hierarchies of simplecusrsoradapter , listadapter (listview adapter), you'll see both subclasses of baseadapter, , therefore why possible.

http://developer.android.com/reference/android/widget/simplecursoradapter.html http://developer.android.com/reference/android/widget/listadapter.html http://developer.android.com/reference/android/widget/baseadapter.html

edit

it not cut , dry subclassing , overriding. may need incorporate of code in cursoradapter parent class overrides, ,

bypass calling super.method(). 

for example, here cursoradapter.java's getview override, may need

explicitly call bindview() 

(ref: http://androidxref.com/4.0.3_r1/xref/frameworks/base/core/java/android/widget/cursoradapter.java

public view getview(int position, view convertview, viewgroup parent) {     if (!mdatavalid) {         throw new illegalstateexception("this should called when cursor valid");     }     if (!mcursor.movetoposition(position)) {         throw new illegalstateexception("couldn't move cursor position " + position);     }     view v;     if (convertview == null) {         v = newview(mcontext, mcursor, parent);     } else {     v = convertview;     }     bindview(v, mcontext, mcursor);     return v; } 

to use xref source code repository, go to

http://androidxref.com/

select api version, , in

"full search"

type

objectname.java

and in list right

"in projects"

scroll down , select

"frameworks"

and search (i find direct , effective way ya want).


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -