0

I am using a JSON database.
In it I prefer to have strings.

If I store something like "singleImage_marginTop" as a string in the JSON file, I can get the string, but how would I convert it into something that I could use here?

image.setPadding(R.dimen.(the_string_to_be_used_here));

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Immy
  • 631
  • 1
  • 5
  • 15

2 Answers2

0
Context context = image.getContext();
int padding = context.getResources().getIdentifier("the_string_to_be_used_here", "dimen", context.getPackageName());
image.setImageResource(padding);

try this.

Ankit Kumar
  • 3,663
  • 2
  • 26
  • 38
0

I tried to use it for a listview and for me non of the above mentioned solutions worked.

Instead I retreated to using a string to identify the given view's intended properties and based on that string I set the attributes for the different types of views in the listadapter.

It was a lot easier and safer that way.

Immy
  • 631
  • 1
  • 5
  • 15