What I am trying to do is put multiple images without the out of memory problem so I'm using the method PutImage() and trying to put the image in the ImageView but from the Activity not the XML file
Here is my XML code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true" android:alwaysDrawnWithCache="false">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
And here is the activity
public class RecipeBanana extends Activity {
ImageView v;
Button button;
Context localcontext = null;
public static Drawable getAssetImage(Context context, String filename) throws IOException {
AssetManager assets = context.getResources().getAssets();
InputStream buffer = new BufferedInputStream((assets.open("drawable/" + filename + ".jpg")));
Bitmap bitmap = BitmapFactory.decodeStream(buffer);
return new BitmapDrawable(bitmap);
}
public void PutImage(ImageView v, String x){
try {
v.setImageDrawable(Drawable.createFromStream(localcontext.getAssets().open("flags/" + x + ".jpg"), null));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipe_banana);
ImageView v=(ImageView) findViewById(R.id.imageView1);
PutImage(v,"bananarecipe");
addListenerOnButton();
}