[android-developers] Re: Simple Cursor Adapter - List View
Hi, You might find useful to set a ViewBinder for the adapter. Have a look at this interface for the SimpleCursorAdapter http://developer.android.com/reference/android/widget/SimpleCursorAdapter.ViewBinder.html There's only one method which is invoked for each column-to-view bind and it gives you the cursor and the column index so you can easily retrieve the value of a column and based on that evaluate if you want to make the view visible or not by setting the visibility invoking the method setVisibility(). Cheers, On Jun 9, 8:49 pm, sateesh devabhaktuni sateesh@gmail.com wrote: I have table with 3 columns which is binded to an XML document with three text views. String[] from = new String[]{A,B,C}; int [] to = new int[] {R.id.a,R.id.b,R.id.c}; Where R.id.a, R.id.b, R.id.c - TextView Depending on the value store in the third column, I have to decide whether i should display this row or not How should, I go about with this. This is what I have so far : SimpleCursorAdapterentry = newSimpleCursorAdapter(this, R.layout.addrow, vCursor , from , to); setListAdapter(entry); If you can provide me an example, that would be really helpful. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Simple Cursor Adapter - List View
You should create your own adapter (probably derived from SimpleCursorAdapter) that does this in its bindView method. On Tue, Mar 17, 2009 at 11:57 PM, Markiv vikramshe...@gmail.com wrote: I have table with 3 columns which is binded to an XML document with three text views. String[] from = new String[]{A,B,C}; int [] to = new int[] {R.id.a,R.id.b,R.id.c}; Where R.id.a, R.id.b, R.id.c - TextView Depending on the value store in the third column, I want to change the text color in R.id.c How should, I go about with this. This is what I have so far : SimpleCursorAdapter entry = new SimpleCursorAdapter(this, R.layout.addrow, vCursor , from , to); setListAdapter(entry); If you can provide me an example, that would be really helpful. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Simple Cursor Adapter - List View
Here is an example of the the simplest way I have found to do this type of thing. public class IconCursorAdapter extends SimpleCursorAdapter { IconCursorAdapter(Context context, int layout, Cursor cursor,String[] from, int[] to) { super(context, layout, cursor, from, to); this.setViewBinder(new IconViewBinder()); } } public class IconViewBinder implements SimpleCursorAdapter.ViewBinder { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view instanceof TextView) { ((TextView) view).setText(cursor.getString(columnIndex)); return true; } if (view instanceof ImageView) { String listType = cursor.getString(columnIndex); if (listType.equals(wish_list)) { ((ImageView) view).setImageResource(R.drawable.lander_plain); return true; } if (listType.equals(todo_list)) { ((ImageView) view).setImageResource(R.drawable.lander_firing); } else { ((ImageView) view).setImageResource(R.drawable.lander_crashed); } return true; } return false; } } On Mar 17, 11:57 pm, Markiv vikramshe...@gmail.com wrote: I have table with 3 columns which is binded to an XML document with three text views. String[] from = new String[]{A,B,C}; int [] to = new int[] {R.id.a,R.id.b,R.id.c}; Where R.id.a, R.id.b, R.id.c - TextView Depending on the value store in the third column, I want to change the text color in R.id.c How should, I go about with this. This is what I have so far : SimpleCursorAdapter entry = new SimpleCursorAdapter(this, R.layout.addrow, vCursor , from , to); setListAdapter(entry); If you can provide me an example, that would be really helpful. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---