0

I am working with an onItemClick method on a ListActivity. I want to use putExtra to insert an array based on the position of the clicked item.

The categories array returns one null in the array. Obviously the @array/main does not work. Can anyone help? The code and XML is below.

String[] categories = getResources().getStringArray(R.array.categories);
Intent i = new Intent(parent.getContext(), CategoriesActivity.class);
i.putExtra("categories", categories[position]);
startActivity(i);   

<array name="categories">
    <item>@array/main</item>
</array>

<string-array name="main">
<item>News</item>
<item>Sport</item>
<item>Business</item>
<item>Comment</item>
<item>Life</item>
<item>Society</item>
<item>Culture</item>
<item>Blogs</item>
 </string-array>
shinokamparos
  • 75
  • 1
  • 7

2 Answers2

0

It seems that this would work.

String[] categories = getResources().getStringArray(R.string.main);
Intent i = new Intent(parent.getContext(), CategoriesActivity.class);
i.putExtra("categories", categories[position]);
startActivity(i);  
PearsonArtPhoto
  • 38,970
  • 17
  • 111
  • 142
0

It should be,

Resources res = getResources();
TypedArray ta = res.obtainTypedArray(R.array.categories);

Further you can iterate it using an answer of StackOverflow itself.

Community
  • 1
  • 1
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242