gpt4 book ai didi

java 安卓 getResources().getIdentifier()

转载 作者:搜寻专家 更新时间:2023-10-30 19:52:01 25 4
gpt4 key购买 nike

如何从 R. 获取 id 的 int id 值?当我使用 getIdentifier 时,它只返回 0

 int i = getArguments().getInt(SELECTION_NUMBER);
String drawerSelection = getResources().getStringArray(R.array.drawerSelection_array)[i];

int panelId = this.getResources().getIdentifier(drawerSelection.toLowerCase(),"id",getActivity().getPackageName());

编辑

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
android:id="@+id/Bus_Schedules"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

</LinearLayout>

日志

06-10 21:24:30.372: I/System.out(3572): Selection = Bus_Schedules
06-10 21:24:30.372: I/System.out(3572): panelId = 0

R.java

    public static final class id {
public static final int Bus_Schedules=0x7f090004;
public static final int basemenu=0x7f090005;
public static final int content_frame=0x7f090001;
public static final int drawer_layout=0x7f090000;
public static final int left_drawer=0x7f090002;

最佳答案

问题似乎是您正在将 drawerSelection 转换为小写。正如 R.java 文件中清楚的那样,标识符的大小写得到了保留。尝试调用:

int panelId = this.getResources().getIdentifier(drawerSelection,"id",getActivity().getPackageName());

关于java 安卓 getResources().getIdentifier(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16862000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com