I try to set a drawable into an ImageView. The source depends on the two digit day-num in month (stored in today
). My API-Level is 17 (The Fairphone 1).
On the virtual devices I can see the picture. But when I install the app on my real phone, the ImageBox is there but empty (white).
This is the code where I set the Image:
ImageView image = (ImageView) findViewById(R.id.startImg);
String uri = "s_"+Integer.parseInt(today);
int imageResource = getBaseContext().getResources().getIdentifier(uri, "drawable", getPackageName());
image.setImageResource(imageResource);
This is my Layout-File:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textColor="@color/colorAccent"
android:textSize="20dp"
android:paddingBottom="16dp"
android:id="@+id/textView"
android:textAlignment="center"
android:textStyle="bold"
android:typeface="serif" />
<ImageView
android:contentDescription="Bild"
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/startImg" />
<GridView
android:id="@+id/DatesGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
>
</GridView>
</LinearLayout>
The LogCat says nothing.
But I checked the App on a Phone on API-Level 22 (The Fairphone 2). Now the app crashes because of a wrong imageResource
.
Question: Why can I see the picture in my Virtual Devices but not on my real device?