Pregunta

I need a way to use strings instead of "PERFORMANCE", "MALI"...I tried to sostitute them by "@string/resource_name" but it doesn t work, when I open the menu it shows instead of the linked name "@string/resource_name".

MainActivity:

 //Show the items into the menu.
@Override
protected NavDrawerActivityConfiguration getNavDrawerConfiguration() {

    NavDrawerItem[] menu = new NavDrawerItem[] {

            //This sets the name, mine is a multilanguage app so I wanna find a way to use @string/resource instead
            //of "PERFORMANCE", ecc.
            NavMenuItem.create(1,"PERFORMANCE", "", false, this),
            NavMenuItem.create(2, "MALI", "", false, this), 
            NavMenuItem.create(3, "BATTERY", "", false, this),
            NavMenuItem.create(4, "CPU", "", false, this), 
            NavMenuItem.create(5, "MISC", "", false, this),
            NavMenuItem.create(6, "NET", "", false, this),
            NavMenuItem.create(7, "HELP", "", false, this),
            NavMenuItem.create(8, "GUIDE", "", false, this)};

    NavDrawerActivityConfiguration navDrawerActivityConfiguration = new NavDrawerActivityConfiguration();
    navDrawerActivityConfiguration.setMainLayout(R.layout.main);
    navDrawerActivityConfiguration.setDrawerLayoutId(R.id.drawer_layout);
    navDrawerActivityConfiguration.setLeftDrawerId(R.id.left_drawer);
    navDrawerActivityConfiguration.setNavItems(menu);
    navDrawerActivityConfiguration.setDrawerShadow(R.drawable.drawer_shadow);       
    navDrawerActivityConfiguration.setDrawerOpenDesc(R.string.drawer_open);
    navDrawerActivityConfiguration.setDrawerCloseDesc(R.string.drawer_close);
    navDrawerActivityConfiguration.setBaseAdapter(
        new NavDrawerAdapter(this, R.layout.navdrawer_item, menu ));
    return navDrawerActivityConfiguration;
}

NavmenuItem:

    public class NavMenuItem implements NavDrawerItem {

public static final int ITEM_TYPE = 1 ;

private int id ;
private String label ;  
private boolean updateActionBarTitle ;

private NavMenuItem() {
}

public static NavMenuItem create( int id, String label, String icon, boolean updateActionBarTitle, Context context ) {
    NavMenuItem item = new NavMenuItem();
    item.setId(id);
    item.setLabel(label);
    item.setUpdateActionBarTitle(updateActionBarTitle);
    return item;
}

@Override
public int getType() {
    return ITEM_TYPE;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getLabel() {
    return label;
}

public void setLabel(String label) {
    this.label = label;
}


@Override
public boolean isEnabled() {
    return true;
}

@Override
public boolean updateActionBarTitle() {
    return this.updateActionBarTitle;
}

public void setUpdateActionBarTitle(boolean updateActionBarTitle) {
    this.updateActionBarTitle = updateActionBarTitle;
}

}

NavdrawerItem:

 public interface NavDrawerItem {
public int getId();
public String getLabel();
public int getType();
public boolean isEnabled();
public boolean updateActionBarTitle();

}

¿Fue útil?

Solución

Are you just looking for:

getString(R.string.name);  

?

You need a context. In fragments or activities you can just call getString but if that's not working for whatever reason it's just a shortcut to

context.getResources().getString(R.string.name);

Otros consejos

Try it like this:

NavDrawerItem[] menu = new NavDrawerItem[] {

        //This sets the name, mine is a multilanguage app so I wanna find a way to use @string/resource instead
        //of "PERFORMANCE", ecc.
        NavMenuItem.create(1,getString(R.string.performance_name), "", false, this) 
....
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top