0
votes

I am in trouble how can I access the drawable icons.png inside in the drawable folder (-hdpi,-mdpi,-xhdpi,-xxhdpi,-xxxhdpi) ?. because I want to place it to my listview. I am using api 23

MainActivity.java

public class MainActivity extends AppCompatActivity {
 private String somevar;

 Integer[] myImg= {
        ContextCompat.getDrawable(this,R.drawable.)//it's not recognizing.


    };

     ....
      ....
}

enter image description here

3
i think it will achieve using getIdentifier() try this link : .developer.android.com/intl/es/reference/android/content/res/…Vishal Thakkar
Try getting the drawable-? folders out of drawable, as a direct child of res. Also, make drawable a separate folder - also a child of res, and put a copy of the images (the size you want) inside it. See structure here: developer.android.com/guide/topics/resources/…Alaa M.
so I make a copy of my icons under my drawable folder ?jemz

3 Answers

2
votes

If you're using an Integer array, pass the resource ids instead of passing the drawable objects. Otherwise use an array of drawables instead.

1
votes

Convert Integer array

Integer[] myImg= {
ContextCompat.getDrawable(this,R.drawable.)//it's not recognizing.
};

to Drawable array:

Drawable[] myImg= {
    ContextCompat.getDrawable(this,R.drawable.)//Now it will recognize it.
};
1
votes

First check if your *.png exist in project, then rebuild your project.

If u want use IntegerArray then:

Integer[] myImg= {
    R.drawable.yourImageName1,
    R.drawable.yourImageName2
    ....
};

R.drawable.yourImageName1 is an Integer.

~.getDrawable(..); returns Drawable.