ArrayAdapter<String> cannot add(R.string.xxx01)

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

ArrayAdapter<String> cannot add(R.string.xxx01)

Postby slashgill » Thu Jan 28, 2010 4:12 pm

hi,

in my string.xml:
<string name="xxx01">example</string>

when i try to code like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ArrayAdapter<String> adp =new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
  2. adp.add(R.string.xxx01);
  3.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

i will got a error message like this:
The method add(String) in the type ArrayAdapter<String> is not applicable for the arguments (int)

In order to solve it, i use a stupid method like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ArrayAdapter<String> adp =new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
  2. TextView temp_text = new TextView(this);
  3. temp_text.setText(R.string.xxx01);
  4. String temp_str = (String) temp_text.getText();
  5. adp.add(temp_str);
  6.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Does any one have a good solution? :?
Thanks.
slashgill
Junior Developer
Junior Developer
 
Posts: 16
Joined: Mon Jan 25, 2010 5:14 am

Top

Postby grzegorz.zajac » Thu Jan 28, 2010 6:08 pm

Should be:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. adp.add(getString(R.string.xxx01));
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Everything about this + examples are in reference guide & samples.

Regards,
Grzesiek
grzegorz.zajac
Developer
Developer
 
Posts: 39
Joined: Wed Feb 18, 2009 8:37 pm
Location: Krakow/Poland

Postby slashgill » Fri Jan 29, 2010 1:55 pm

It works.
Thanks for your help :D
slashgill
Junior Developer
Junior Developer
 
Posts: 16
Joined: Mon Jan 25, 2010 5:14 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 10 guests