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. How to put a Label value in Spinner e.g <Choose>

How to put a default value in Spinner ,the value which is not coming
from DB.. Some thing like

<Choose Contact>
or
<Select>

On the Spinner it should show something like this,and then when user
selects it,then he/she actually can get the value from DB or whatever
set.
--~--~---------~--~----~------------~-------~--~----~

2. Accessing the Task Manager

Is there a way to launch the Task Manager(the same one as when you
hold down the home button) from your application?

Thanks

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

3. Problem with Handler and messages

4. Linux help command?

5. If delete R.java, how how can recover it?

6. ListView Choices: What the devil is happening?

7. Create Data Base