Kostya

Brilliant! I'm going to get stuck in with this, this weekend and hopefully
get it right. I did try something similar to what you mentioned, but I
wasn't sure if i was on the right track and when it didn't work (most likely
something I did wrong) moved on. I have a much better idea of what you mean
now and what the gist should be.

I honestly can't thank you enough for your advice. Hopefully I won't need to
bother you again.

Kind regards

On Fri, Feb 11, 2011 at 2:40 PM, Kostya Vasilyev <kmans...@gmail.com> wrote:

>  Richard,
>
> To keep it simple, I would recommend:
>
> 1. Override bindChildView and set your floating point value "manually". You
> can get the value from the cursor, call findViewById() on the view that's
> passed it to get the TextView that should show the value, format the value
> as a string, and then call
> amountTextTiew.setText(formattedAmountValueString);
>
> 2. Call the base class bindChildView from your own to take care of all the
> other data items / views except the floating point one.
>
> 3. Pass from/to arrays to SimpleCursorTreeAdapter that have all data item /
> view IDs - except the floating point amount data item, which is handled by
> pt. 1.
>
> With this, you won't need to do too much work in your overrides, won't need
> to copy and modify any code from Android, won't need access to private data
> members of SimpleCursorTreeAdapter, and won't need to rely on ViewBinder
> that only appeared in API level 5:
>
>
> http://developer.android.com/reference/android/widget/SimpleCursorTreeAdapter.ViewBinder.html
>
> -- Kostya
>
> PS - I find it very useful to have Android framework source code in
> Eclipse. Instead of hunting through the source code repository, it lets me
> open source code by class name, by pressing Ctrl+Shift+T.
>
> 11.02.2011 12:38, Richard Marsh пишет:
>
> Kostya,
>
> Thank you SO much for taking the time to reply. I guess the next rookie
> question would be: "Do I get the source code for the SimpleCursorTreeAdapter
> and modify it to build my own"
>
> I was playing around with that idea and when I tried to overwrite the
> method below, my custom adapter didn't recognize the variables mChildFrom
> and mChildTo. I assumed that with apis after level 4 had changed the parent
> classes that define and assign those arrays.
>
> @Override
> protected void bindChildView(View view, Context context, Cursor cursor,
> boolean isLastChild) {
> bindView(view, context, cursor, mChildFrom, mChildTo);
> }
>
> I'm ok with the idea of building my own adapter from the "base" adapters.
> I'm just not sure how to access the source code, what is derived from the
> parent classes etc. I'm sorry if these questions seems stupid, but I've only
> been at this for about a month.
>
> Alos, if I look at the documentation here
> http://developer.android.com/reference/android/widget/SimpleCursorTreeAdapter.htmland
>  filter it on API level 4, I don't see a bindView method. Is the method
> inherited?
>
> One last question, to be clear on your suggestion, is that I override the
> bindChildView and bindGroupView methods?
>
> Again, thank you for replying.
>
> On Fri, Feb 11, 2011 at 11:26 AM, Kostya Vasilyev <kmans...@gmail.com>wrote:
>
>> Richard,
>>
>> Adapter view binders are only a convenience feature, and you can always
>> skip to the real stuff.
>>
>> SimpleCursorTreeAdapter has this private method where mViewBinder is used:
>>
>> private void bindView(View view, Context context, Cursor cursor, int[]
>> from, int[] to) {
>> ViewBinder binder = mViewBinder;
>> for (int i = 0; i < to.length; i++) {
>> if (binder != null) {
>> bound = binder.setViewValue(v, cursor, from[i]);
>> }
>> ... default case for when there is no binder ...
>> }
>> }
>>
>> This method is called from public, API level 1, override-able SDK methods:
>>
>> @Override
>> protected void bindChildView(View view, Context context, Cursor cursor,
>> boolean isLastChild) {
>> bindView(view, context, cursor, mChildFrom, mChildTo);
>> }
>>
>> @Override
>> protected void bindGroupView(View view, Context context, Cursor cursor,
>> boolean isExpanded) {
>> bindView(view, context, cursor, mGroupFrom, mGroupTo);
>> }
>>
>> So - override bindChildView / bindGroupView to format and set the values
>> any way you like. You can even make your own MyBinder class and follow the
>> general structure as above.
>>
>> Also, if you're not using automatic view binding, your might as well
>> derive your adapter from ResourceCursorTreeAdapter.
>>
>> In general, my impression of Simple*Adapter classes is that they are like
>> bicycles for small children (those with little wheels on the sides) - not a
>> bad way to start, but you outgrow them pretty quickly.
>>
>> -- Kostya
>>
>> 11.02.2011 11:41, Richard Marsh пишет:
>>
>>  Hi everyone
>>>
>>> I've been stuck on this issue for a couple of days now and I think I'm
>>> close to murder, so any help would be greatly appreciated.
>>>
>>> First just a little context.
>>>
>>> I have a db with a Budget and Category tables. The fields are _id
>>> ,CategoryID, Item and Amount. The amount is stored as a double. I've written
>>> my own db adapters and they are working no problem. So with lots of reading
>>> and searching I finally get my ExpandablListView to populate using my
>>> slightly modified SimpleCursorTreeAdapter. My custom adapter just changes
>>> the GetChildrenCursor to return the children associated with each category.
>>>
>>> Now here's the problem:
>>>
>>> The amount value is shown in the list and I would like to format how the
>>> value is displayed into a local currency. The formatting isn't the issue.
>>> The issue is that I can use a ViewBinder but only if I use API level 5 and
>>> up. But I want to use API level 4 and up.
>>>
>>> So how do I change the way the data is displayed in my list items,
>>> without having to use a viewbinder... or at least, working withing the API 4
>>> framework.
>>>
>>> ANY advice or ideas would be appreciated!
>>>
>>> Kind regards --
>>> 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
>>>
>>
>>
>>   --
>> Kostya Vasilyev -- WiFi Manager + pretty widget --
>> http://kmansoft.wordpress.com
>>
>>
>> --
>> 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
>>
>
> --
> 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
>
>
>
> --
> Kostya Vasilyev -- WiFi Manager + pretty widget -- 
> http://kmansoft.wordpress.com
>
>  --
> 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
>

-- 
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

Reply via email to