getTextArray() and getStringArray()

423 views
Skip to first unread message

Macarse

unread,
Dec 7, 2010, 10:21:48 AM12/7/10
to robol...@googlegroups.com
In my app I used:
CharSequence[] optionsText =
getResources().getTextArray(R.array.search_options);

When I did the test it failed with a nullpointer. So I guessed that
getTextArray() didn't have an implementation in the ShadowResources.
Well it doesn't have it but there is a getStringArray().

The only difference between the is that:

* getTextArray returns CharSequence[]
* getStringArray return String[]

I would make getTextArray call getStringArray.
What do you think?

Second thing
Something is broken in both:

If you define your array as something
<string-array name="search_options">
<item>@string/search_by_property_type</item>
<item>@string/search_by_operation_type</item>
<item>@string/search_by_location</item>
<item>@string/search_by_price_range_from</item>
<item>@string/search_by_price_range_to</item>
<item>@string/search_by_currency</item>
</string-array>

When you get the String[] it doesn't do the conversion. so you get
"@string/search_by_property_type".

How should we fix this?

Thanks!

PS: This is my last new thread. I promise! :D

Tyler Schultz

unread,
Dec 7, 2010, 2:04:47 PM12/7/10
to robol...@googlegroups.com
Hi Macarse, 

For question 1: 
We'll have to investigate and add implementations to the shadows for these.  We think your suggested implementation of getTextArray seems reasonable.


For question 2:

We ran into the same issue when dealing with colors.  
Check out ColorResourceLoader as an implemenation example.  It seems like there's a refactoring to be made to pull out that logic for all the occurrences similar to this.


Let us know if you're in the process of implementing shadows for these. In the mean time we'll add stories to our tracker project for us to implement.

--Phil & Tyler

Macarse

unread,
Dec 7, 2010, 6:03:34 PM12/7/10
to robol...@googlegroups.com
On Tue, Dec 7, 2010 at 4:04 PM, Tyler Schultz <tylers...@gmail.com> wrote:
> Hi Macarse,
> For question 1:
> We'll have to investigate and add implementations to the shadows for these.
>  We think your suggested implementation of getTextArray seems reasonable.
>

k

> For question 2:
> We ran into the same issue when dealing with colors.
> Check out ColorResourceLoader as an implemenation example.  It seems like
> there's a refactoring to be made to pull out that logic for all
> the occurrences similar to this.
>

I don't know what you are willing to pull out.
Creating some sort of class that gets id as strings starting with @
and returns the id of it?

From what I have read in ColorResourceLoader something like this
should be added to processNode @ StringArrayResourceLoader:

String value = childNode.getTextContent();
if ( value.startsWith("@string") ) {
// get StringResourceLoader
StringResourceLoader srl;
value = srl.getValue(value.substring(1));
}

But I don't know how I can get a StringResourceLoader instance :(

> Let us know if you're in the process of implementing shadows for these. In
> the mean time we'll add stories to our tracker project for us to implement.

I can work on this but let's decide which is the best way of implementing it.

Tyler Schultz

unread,
Dec 7, 2010, 8:11:25 PM12/7/10
to robol...@googlegroups.com
Re: deciding on the best way: Go ahead and do whatever works for you and perhaps Phil and I can take a look later this week for refactoring opportunities.

--Phil & Tyler


P.S. thanks for the pull request, we'll get to it soon.

Macarse

unread,
Dec 8, 2010, 7:07:16 AM12/8/10
to robol...@googlegroups.com
Just did the pull request with my implementation.

I don't like the fact that I need to send an instance of
StringResourceLoader in the constructor :(

Reply all
Reply to author
Forward
0 new messages