Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting images from internet and store them in internal memory dynamicly in Android
    text
    copied!<p>I have an Activity which is used as an image gallery and works quite well. But it loads images from integer array which has references from drawables. And what I want to do is getting images from internet and store them in internal memory then use them in my gallery.</p> <p>Here is my code below. Any help will be appreciated.</p> <pre><code>import okan.apps.tabbar.R; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.animation.AnimationUtils; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.ViewSwitcher.ViewFactory; public class Activities extends Activity implements ViewFactory { ImageSwitcher imageSwitcher ; Integer[] imageList = { R.drawable.gallery, R.drawable.menu, R.drawable.promotion, R.drawable.info, R.drawable.activities }; int curIndex=0; int downX,upX; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activities_main); imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher); imageSwitcher.setFactory(this); imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in)); imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out)); imageSwitcher.setImageResource(imageList[curIndex]); imageSwitcher.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { downX = (int) event.getX(); Log.i("event.getX()", " downX " + downX); return true; } else if (event.getAction() == MotionEvent.ACTION_UP) { upX = (int) event.getX(); Log.i("event.getX()", " upX " + downX); if (upX - downX &gt; 100) { //curIndex current image index in array viewed by user curIndex--; if (curIndex &lt; 0) { curIndex = imageList.length-1; } imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(Activities.this,R.anim.slide_in_left)); imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(Activities.this,R.anim.slide_out_right)); imageSwitcher.setImageResource(imageList[curIndex]); //GalleryActivity.this.setTitle(curIndex); } else if (downX - upX &gt; -100) { curIndex++; if (curIndex &gt; 4) { curIndex = 0; } imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(Activities.this,R.anim.slide_in_right)); imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(Activities.this,R.anim.slide_out_left)); imageSwitcher.setImageResource(imageList[curIndex]); //GalleryActivity.this.setTitle(curIndex); } return true; } return false; } }); } public View makeView() { ImageView i = new ImageView(this); i.setScaleType(ImageView.ScaleType.FIT_CENTER); return i; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload