Android dynamically adding images from xml into gridview
Okay so here my issue, I
have a list of items that when a user clicks one, it gets added to a shared preference file which looks like this: <map>
<string name="Some Name">R.drawable.somename</string>
</map>
Using this code:
prefEdit.putString(title[positio开发者_如何学JAVAn],imgString[position]);
prefEdit.commit();
What I want to do is place R.drawable.somename from the xml file into a grid view as an image in place of:
private Integer[] mThumbIds = {
R.drawable.archery, R.drawable.aviation,
R.drawable.archery, R.drawable.aviation,
R.drawable.archery, R.drawable.aviation,
R.drawable.archery, R.drawable.aviation,
R.drawable.archery, R.drawable.aviation
};
Currently the user can select up to 130 different items that they can add to the grid view.
Any suggestions?
It would be better to just have the xml store the base name, ("somename", "archery", "aviation"). Then you could get the id doing this.
int id = getResources().getIdentifier("archery", "drawable", getPackageName());
In this example if your drawable was R.drawable.archery then id would = R.drawable.archery. You could store the strings in the xml and get the ids this way.
精彩评论