views:

31

answers:

2

This should be simple, but driving my crazy.

I have the following in my layout, not problems.

<TextView
    android:id="@+id/birdinfo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#00009c"
    android:text="The Robin is a popular bird"
/>

Then I have these arrays which are set up with the list of string resources I have

 private Integer[] DetailIds = {            
         R.string.barnaclegoose,
         R.string.barnowl,
         R.string.bewicksswan,
         R.string.blackbird,
         R.string.blackcap_male};

So I simply want to do this!

    TextView detail = (TextView)findViewById(R.id.birdinfo);
    detail.setText(DetailIds[0]);
    setContentView(R.layout.main);

But this causes a force close error.

The string resource looks like this ( without header and footer info of course

<string name="barnaclegoose">What a wonderful goose!</string>

Added to this problem is if I use the resource directly to the resource

detail.setText(R.string.barnaclegoose);

For example, I still get a null exception! I'm sure I've done this before, but maybe I'm missing the obvious???

Any ideas appreciated.

( Eclipse, Android 1.5, Emulator with 1.5 )

+1  A: 

hi

are you sure, you can hold Strings within an Integer-Array? ;-)

poeschlorn
A: 

Thanks for the answer. but if you mean R.string.barnaclegoose for example, this is an integer value for the ID pointing to the string itself in the resource.

Anyway, I finally got it working by just creating the view inline instead of using an resource view.

For example

TextView t= new TextView(ctx);
     t.setId(2);
     t.setTextColor(Color.BLACK);
     t.setText(DetailIds[bird]);

    mLinearLayout.addView(t,params);
    mLinearLayout.setBackgroundColor(Color.WHITE);
    setContentView(mLinearLayout);

And that works perfectly.

Greg Martin