listview - Android: Custom CursorAdapter to alternate resources -
this problem has been stuck while in head.
what need do: show listview alternating resources items in listview.
what problem: far can alternate resources , show no data, or show data not alternate resources. first item works every time, not form there onwards. think i'm close can't think going wrong...
what have done: have used custom simple cursor adapter.
where code:
public class dialogcursor extends simplecursoradapter { private linearlayout wrapper; private textview burbuja; public dialogcursor(context context, int layout, cursor c, string[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); // todo auto-generated constructor stub } @override public view getview(int position, view convertview, viewgroup parent) { view row = convertview; if (row == null) { context context = parent.getcontext(); layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); row = inflater.inflate(r.layout.dialogo_row, parent, false); } burbuja = (textview) row.findviewbyid(r.id.idiomaselec); wrapper = (linearlayout) row.findviewbyid(r.id.wrapper); //get reference row view view = super.getview(position, convertview, parent); log.d("dialogo","enters getview"); log.d("dialogo",integer.tostring(position)); //check odd or set alternate colors row background if(position % 2 == 0){ log.d("dialogo","even"); burbuja.setbackgroundresource(r.drawable.bubble_green); wrapper.setgravity(gravity.left); } else { log.d("dialogo","not even"); burbuja.setbackgroundresource(r.drawable.bubble_yellow); wrapper.setgravity(gravity.right); } return row; }
}
the cursor adapter called other class (just showing relevant part)
string[] = new string[] { dialogotable.table_dialogo + "." + columna };
// fields on ui map final int[] = new int[] { r.id.idiomaselec};
log.d("dialogo","entra en filldata2"); getloadermanager().initloader(0, null, this); if (bot) { log.d("dialogo","entra en filldata2.5"); getloadermanager().restartloader(0, null, this); } adapter2 = new dialogcursor(this, r.layout.dialogo_row, null, from, to, 0); setlistadapter(adapter2);
and output: if return row (last line of code) background resources in right place no data if return view (last line of code) data first item has right background resources.
one last note: have followed example http://adilsoomro.blogspot.com/2012/12/android-listview-with-speech-bubble.html dont want create class message since wnat data db.
thank :)
in similar case able have custom cursoradapter alternate resources based on cursor position. put following code in bindview entryview passed in view. overriding getview @ all.
if(cursor.getposition()%2 == 1){ entryview.findviewbyid(r.id.title_relative).setbackgroundcolor(getresources().getcolor(r.color.orange)); }else{ entryview.findviewbyid(r.id.title_relative).setbackgroundcolor(getresources().getcolor(r.color.blue)); }
Comments
Post a Comment