Questions tagged [getstring]
150 questions
30
votes
3 answers
Why might Resources.getString() intermittently return strings from the wrong locale?
I have an Android application with English strings in values/strings.xml. For each string in that file, I have an entry in values-ja/strings.xml with the Japanese translation of that string. If I set the emulator, a Nexus One or Nexus S to Japanese,…

Bob Whiteman
- 2,481
- 2
- 23
- 27
30
votes
6 answers
Android: getString(R.string) in static method
When programming for Android sometimes you have to use static methods. But when you try to access you resources in a static method with getString(R.string.text) you'll get an error. Making it static doesn't work.
Does anyone knows a good way around…

Saren Inden
- 3,450
- 4
- 32
- 45
16
votes
4 answers
Getting null terminated string from System.Text.Encoding.Unicode.GetString
I have an array of bytes that I receive from an external entity. It is a fixed size. The bytes contain a unicode string, with 0 values to pad out the rest of the buffer:
So the bytes might be:
H \0 E \0 L \0 L \0 \0 \0 \0 \0 \0 ... etc
I'm…

DougN
- 4,407
- 11
- 56
- 81
15
votes
2 answers
R.string; get string from dynamic key name
Possible Duplicate:
Dynamic Resource Loading Android
In Android, I can load a string from the resources with String s = getString(R.string.keyName). But I have a list of categories in my database, each one which has a name. How can I take that…

GendoIkari
- 11,734
- 6
- 62
- 104
9
votes
5 answers
Cannot I do a getResources.getString dynamically?
I'm trying to fill a Spinner with the values of some Strings of string.xml. I'm trying to do like that:
final List list = new ArrayList();
for (int i = 0; i < 86; i++) {
String resource = "R.string." + ntpServers[i][0];
…

Víctor Martín
- 3,352
- 7
- 48
- 94
7
votes
5 answers
When to use getString()
I am wondering about the getString().
I can see that doing getString(R.string.some_text) works. Also getResources().getString(R.string.connection_error) works.
So my question is why should we use the getString or when?
Thanks!

roiberg
- 13,629
- 12
- 60
- 91
6
votes
1 answer
The method getResources() and context is undefined for the type
I use the getString() to become String from string.xml.
In my class (non-activity) does not work:
context.getResources().getString()
getResources().getString()
context.getResources().getString()
How do I get the String to this class?
public class…

user1878413
- 1,813
- 4
- 18
- 24
6
votes
4 answers
The method getString(int) is undefined for the type Apps
How do I fix this error. All the three strings on the bottom get the following error "the method getString(int) is undefined for the type Apps". Please help, im such a noob.
package com.actionbarsherlock.sample.fragments;
import…

idroid8
- 177
- 1
- 4
- 14
5
votes
3 answers
Android - ClassCastException?
@Override
public void onPause()
{
super.onPause();
save(notes.itemSelected);
}
@Override
public void onResume()
{
super.onResume();
notes.itemSelected.clear();
notes.itemSelected = load();
}
@Override
public void onRestart()
{
…

Varundroid
- 9,135
- 14
- 63
- 93
5
votes
2 answers
Android Cursor? how to read object data?
i know a Cursor has method for get String, Int, etc
but isn't there somethings as
mycursor.GetObject(index)
I want to create a dynamic method which returns an object and I only cast it.
or is it possible use
mycursor.GetString(index) for any type?…

angel
- 4,474
- 12
- 57
- 89
4
votes
1 answer
getString returning wrong language string
In the onCreate on the Application class of my app I have this code
Locale current = getResources().getConfiguration().locale;
String language = Utils.getPhoneLanguage();
String text = getString(R.string.text);
I've set the phone…

Boldijar Paul
- 5,405
- 9
- 46
- 94
4
votes
2 answers
Using intent.getStringExtra from within an activity
I am relatively new to android. I have two applications A and B. I have an activity in A, lets name it x, that would launch the application B. Now the intent sent by x contains StringExtra that I want the Starting activity in B to use. Is there a…

Lakshmie
- 331
- 6
- 17
4
votes
5 answers
Byte to String to byte conversion puzzling error
Could anyone please help spot the error? Here's the code:
byte[] oriBytes = { 0xB0, 0x2D }; // oriBytes -> 0xB0, 0x2D
string oriInStr = Encoding.ASCII.GetString(oriBytes); // oriInStr -> "?-"
oriBytes =…

sam byte
- 697
- 9
- 11
4
votes
6 answers
MonoGame Key Pressed String
In MonoGame, how can I read which keyboard key is pressed in the form of a String?
I have tried String pressedKey = Keyboard.GetState().ToString();, but it gives me "Microsoft.Xna.Framework.Input.KeyboardState".

Evorlor
- 7,263
- 17
- 70
- 141
3
votes
1 answer
get and set listPreference from another activity not working
I'm trying to get and set a listPreference value from different activities and it's not working.
When I read and write it from my main activity, it only keeps whatever I write, so I'm assuming that I'm not targeting the listPreference correctly when…

Toclmi
- 99
- 2
- 13