Spaces in strings.xml strings

by droozen » Wed, 04 Mar 2009 02:01:21 GMT


Sponsored Links
 So, we're supposed to be using our strings.xml to construct most or
all of our strings, right? I had a situation where I wanted to display
to the user "Some string blah blah " + some value. So I put two views
in a horizontal LinearLayout, with my "Some string blah blah " (with
that space on the end, no quotes) in the strings.xml. I reference the
string in my first view, then set the value in the second view.
However, if I set it up like this, the space at the end of my string
gets trimmed off, which doesn't look pretty. My workaround was not to
use the strings.xml and place the "Some string blah blah " (no quotes)
directly in the android:text parameter of the TextView.

Any idea if there is a better way to do this? Or should I submit a bug
to Android about this?

--~--~---------~--~----~------------~-------~--~----~



Spaces in strings.xml strings

by Marco Nelissen » Wed, 04 Mar 2009 02:30:48 GMT


 


Instead of breaking up the string and using two TextViews to display
what is supposed to be a single string, you should use a single
TextView and a string in your resource like "Some string blah blah
%s", and then use the version of Context.getString() that takes
format-arguments.

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Spaces in strings.xml strings

by droozen » Thu, 05 Mar 2009 07:07:18 GMT


 Okay, I see, but I guess I didn't explain my entire issue. I don't
know a whole lot about working with the SQLite databases, so right now
I'm able to do what was done in the Notepad tutorial, get values from
the database and tie them to ids of TextViews to display them. But
part of the list I wanted to put together some of the values into a
sentence. So I split it up into several text views. I have "Some
string blah blah ", then the next TextView holds the value returned.
Is there a way I can manipulate the data in each row to put it in my
list? I just follow the Notepad tutorial right now. :S





--~--~---------~--~----~------------~-------~--~----~



Spaces in strings.xml strings

by Marco Nelissen » Thu, 05 Mar 2009 07:29:15 GMT


 If you want to make sentences, it's still a good idea to put a format
string in the resource and then use that, since you'll be able to
correctly localize your app later on.
To use this with a Cursor and ListView, create a custom Adapter (you
can probably just derive from SimpleCursorAdapter), and override the
bindView() method. Then inside that method you can do whatever you
want to set the text for the views in your list items, including
gathering data from several columns in the database and combining them
in to one string.









--~--~---------~--~----~------------~-------~--~----~



Spaces in strings.xml strings

by Dianne Hackborn » Thu, 05 Mar 2009 10:25:47 GMT


 nd if you just want spaces in specific places in the string, just put it in
quotes or use \ to prevent it from being stripped.

On Wed, Mar 4, 2009 at 3:29 PM, Marco Nelissen <marc...@android.com> wrote:



--
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support. All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~



Spaces in strings.xml strings

by droozen » Thu, 05 Mar 2009 22:56:27 GMT


 Thanks. I'll try it out!







--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Slow emulator

Hi guys,

Pretty new to the whole Android idea, I am buying the HTC hero soon
and would quite like to develop for it. I have found on my PC that the
emulator runs really slowly- to get to actually being able to use my
app when emulating takes around a minute and a half. Can anyone
suggest why? I use Eclipse, with Windows 7 and a good-but-not-amazing
spec laptop. Please help! Thanks

-- 

2. Quiet Here?

It's awfully  quiet for this usually busy group (though not as much as 
the developer group) so thought I would send a test message since there 
have been no messages since Saturday.

--

3. Is that compulsory to use Java developing android apps????

4. Installing Android Tools in Eclipse on Ubuntu

5. Gradient banding on high DPI devices

6. View Flipper Performance with MapView

7. Using a US IR Receiver with Android