getIdentifier is ok, but you should use it this way:
int imageid = getResources().getIdentifier("brazil_flag", "drawable", context.getPackageName());
the first parameter is the name of the resource you are looking for, the second parameter is the type of the resource, the third is the package where to look for.