簡體   English   中英

Android-getResources()。getIdentifier()找不到資源

[英]Android - getResources().getIdentifier() not finding the resource

我有一個xml文件,其中包含以下資源

    <LinearLayout android:id="@+id/t214" android:padding="3dip"></LinearLayout>

    <LinearLayout android:id="@+id/t215" android:padding="3dip"></LinearLayout>

等等

我有以下代碼:

String id = "t" + c.get(Calendar.DAY_OF_WEEK) + c.get(Calendar.HOUR_OF_DAY);
Log.v("calendar", "id string: " + id);
// Get handle of LinearLayout
LinearLayout ll = (LinearLayout) findViewById(CalendarViewActivity.this.getResources().getIdentifier(id, "id", getPackageName()));

根據日志,id字符串變量的值為't214',因此getResources()。getIdentifier()應該返回int標識符,以便可以在findViewById中使用它,但是ll將返回為null。

非常感謝!

我不確定我是否理解這個問題...但是,findViewById()的一般模式建議這樣的代碼:

LinearLayout ll =(LinearLayout)findViewById(R.id.t214);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM