0

click .. i think que is clear pls help me i am new in android and java pls pls..

**private String[] imageList = {"http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/directorio/galerias/ruth_benzacar/artistas/martin_di_girolamo._diosas/198915-1-esl-AR/MARTIN_DI_GIROLAMO._Diosas.jpg","http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/directorio/galerias/ruth_benzacar/artistas/jorge_macchi._la_espera/198929-1-esl-AR/JORGE_MACCHI._La_espera.jpg"};**










public class SequencerActivity extends Activity implements OnClickListener
{
private int imageCounter = 0;
private ImageView imageLoader;

**private String[] imageList = {"http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/directorio/galerias/ruth_benzacar/artistas/martin_di_girolamo._diosas/198915-1-esl-AR/MARTIN_DI_GIROLAMO._Diosas.jpg","http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/directorio/galerias/ruth_benzacar/artistas/jorge_macchi._la_espera/198929-1-esl-AR/JORGE_MACCHI._La_espera.jpg"};**


public void onCreate(Bundle savedInstanceState) 
{
    setContentView(R.layout.parent_frame);//this one is the common parent layout for all image views
    super.onCreate(savedInstanceState);

    /*requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);*/

    //int image1 = R.drawable.image_w_lbl_0;


    //imageLoader.setImageResource(image1);

    ImageButton next = (ImageButton) findViewById(R.id.next);
    ImageButton back = (ImageButton) findViewById(R.id.back);
    next.setOnClickListener(this);
    back.setOnClickListener(this);
    back.setEnabled(false);
    //show the default image
    this.loadImage(imageList[imageCounter]);

}
@Override
public void onClick(View v) 
{

}

private void loadImage(int imagePath)
{
    imageLoader.setImageResource(imagePath);

}
}
atul yadav
  • 307
  • 2
  • 5
  • 12

4 Answers4

1

If you have String values in your imageList array representing resource names,

private String[] imageList = { "image_wo_lbl_0", "image_wo_lbl_1", "image_wo_lbl_2" };

then you can modify the loadImage method:

private void loadImage(final String imagePath)
{
    imageLoader.setImageResource(getResources().
            getIdentifier(imagePath, "drawable", "your.application.package"));
}

If you have urls stored in the imageList array

private String[] imageList = { "file:///somedir/IMAG0001.jpg", 
    "file:///otherdir/IMAG0002.jpg", 
    "file:///somedir/IMAG0003.jpg" };

you can use

private void loadImage(final String imagePath)
{
    imageLoader.setImageURI(Uri.parse(imagePath));
}

When loading images from the web (storing their urls in the imageList):

private String[] imageList = { "http://somedomain/IMAG0001.jpg", 
    "http://otherdomain/IMAG0002.jpg", 
    "http://somedomain/IMAG0003.jpg" };
[...]
private void loadImage(String imagePath)
{
    try
    {
        final URL url = new URL(imagePath);
        final InputStream inputStream = (InputStream)url.getContent();
        Drawable drawable = Drawable.createFromStream(inputStream, "src");
        imageLoader.setImageDrawable(drawable);
    }
    catch (Exception e)
    {
        Log.e("Error", "loadImage", e);
    }
}

For this to work, don't forget to add the android.permission.INTERNET permission to your application in the `androidManifest.xml!

rekaszeru
  • 19,130
  • 7
  • 59
  • 73
  • you can use `imageList` exactly the same as you did in your example, just change the `int` declarations to `String`, since it is a `String[]` array. – rekaszeru May 20 '11 at 11:20
  • how does your url look like? share an item from your `imageList` array, please. – rekaszeru May 20 '11 at 14:20
  • You need to specify the protocol through you get the image, so insert **http://** before the paths items in your list. – rekaszeru May 21 '11 at 05:16
  • thanks for the urls, please see my update for how to load images from the web. – rekaszeru May 21 '11 at 06:27
  • thanks it works and i also posted my answer pls see it,it also works...but problem is i had used this and worked but now problem is that how to show button left and right of image ..means image is displaying in full width ,and in my xml file i had defined wrap_content for imageview but button is not showing on left and right how to solve this..thanks for appreciating me again.... – atul yadav May 21 '11 at 07:13
1

@rekaszeru i had used
private void loadImage(String imagePath) {

  try {

      /* Open a new URL and get the InputStream to load data from it. */

      URL aURL = new URL(imagePath);
      URLConnection conn = aURL.openConnection();
      conn.connect();
      InputStream is = conn.getInputStream();

      /* Buffered is always good for a performance plus. */
      BufferedInputStream bis = new BufferedInputStream(is);

      /* Decode url-data to a bitmap. */
      Bitmap bm = BitmapFactory.decodeStream(bis);

      bis.close();
      is.close();

      /* Apply the Bitmap to the ImageView that will be returned. */

      imageLoader.setImageBitmap(bm);

      //bigView.setImageBitmap(bm);
     // bigView.setScaleType(ImageView.ScaleType.FIT_CENTER);

      imageLoader.setImageBitmap(bm);


  } catch (IOException e) {

      // i.setImageResource(R.drawable.error);

      Log.e("DEBUGTAG", "Remote Image Exception", e);

  }
atul yadav
  • 307
  • 2
  • 5
  • 12
  • @rekaszeru i had used this and worked but now problem is that how to show button left and right of image ..means image is displaying in full width ,and in my xml file i had defined wrap_content for imageview but button is not showing on left and right how to solve this..thanks for appreciating me again.... – atul yadav May 21 '11 at 07:12
  • This is a good solution too! About the layout issue I'd suggest you to open a new thread, to keep StakOverflow's answers clean, focused on solving a specific issue, not serving a single member. This way others might find it helpful as well. And ask the question providing the layout, and specifying exactly, how you need the buttons to be lied out: may they overlap the image area, or the image should be in the area between the two buttons? Thank you! – rekaszeru May 21 '11 at 07:31
0

You should take only one Imageview and set image using setImageResource properties and increase the countervalue when click on next button . You can also use imageswitcher control for solving this problem.

DynamicMind
  • 4,240
  • 1
  • 26
  • 43
0

You can refer to this SO question. Every time your press you have to call that method and change the URL by passing the next element in the array.

Community
  • 1
  • 1
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153