Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created June 24, 2013 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pec1985/5847653 to your computer and use it in GitHub Desktop.
Save pec1985/5847653 to your computer and use it in GitHub Desktop.
Helper to get R. in Titanium Android
package com.pec1985.tigolf;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.util.TiRHelper.ResourceNotFoundException;
public class RHelper {
public static int getString(String str){
try {
return TiRHelper.getApplicationResource("string."+str);
} catch (ResourceNotFoundException e) {
e.printStackTrace();
return 0;
}
}
public static int getLayout(String str){
try {
return TiRHelper.getApplicationResource("layout."+str);
} catch (ResourceNotFoundException e) {
e.printStackTrace();
return 0;
}
}
public static int getId(String str){
try {
return TiRHelper.getApplicationResource("id."+str);
} catch (ResourceNotFoundException e) {
e.printStackTrace();
return 0;
}
}
public static int getDrawable(String str){
try {
return TiRHelper.getApplicationResource("drawable."+str);
} catch (ResourceNotFoundException e) {
e.printStackTrace();
return 0;
}
}
public static int getColor(String str){
try {
return TiRHelper.getApplicationResource("color."+str);
} catch (ResourceNotFoundException e) {
e.printStackTrace();
return 0;
}
}
public static int getRaw(String str){
try {
return TiRHelper.getApplicationResource("raw."+str);
} catch (ResourceNotFoundException e) {
e.printStackTrace();
return 0;
}
}
public static int getXML(String str){
try {
return TiRHelper.getApplicationResource("xml."+str);
} catch (ResourceNotFoundException e) {
e.printStackTrace();
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment