Sunday, 15 January 2012

android - CursorAdapter with separators - how to get proper cursor? -



android - CursorAdapter with separators - how to get proper cursor? -

i'm trying add together separators between views using cursoradapter.

i know how add together separators themselfs, i'm not sure how obtain suitable cursor such task. info stored within cotentprovider backed sqlite database.

separators stored as: _id, name

items stored as: _id, name, ... , separator_id

solutions see far

get separators. each separator independetly retrieve items. think there big overhead... or wrong? join tables on item.separator_id = separator._id , order result field of separator. then, within cursoradapter changes of separator_id , insert separator view. quite messy, think.

is there improve way solve problem?

its improve work enum of separators. in case

public cursor getitemlist(){ homecoming db.rawquery("select * items natural bring together separators on item.separator_id = separators._id"); }

create custom cursoradapter , manage within bindview method in way. layout view separator should contain imageview separator inside.

public class mycursoradapter extends cursoradapter { layoutinflater inflater; public mycursoradapter(context context, cursor c) { super(context, c); inflater = layoutinflater.from(context); }

@override public void bindview(view view, context context, cursor cursor) { //cursor setted requared position, column textview tv1 = (textview)view.findviewbyid(r.id.textview1); textview tv2 = (textview)view.findviewbyid(r.id.textview2); tv1.settext(cursor.getstring(1)); tv2.settext(cursor.getstring(2)); imageview myimageview = (imageview)fimdviewbyid(r.id.my_image_view); if(cursor.getstring(5) == "line"){ myimageview = getresources().getidentifier("yourpackagename:drawable/line.png"); }else if(cursor.getstring(5) == "wave"){ myimageview = getresources().getidentifier("yourpackagename:drawable/wave.png"); ... }

@override public view newview(context context, cursor cursor, viewgroup parent) { //here view each raws homecoming inflater.inflate(r.layout.my_raw_view, parent, false); } }

android android-sqlite android-cursoradapter

No comments:

Post a Comment