Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Am developing image slide show application. I have added all the images to res\drawable-hdpi folder. I want to form the url dynamically and need to load the image to screen dynamically.

On Next Button click event, I need to load the next file from folder
Java
//strings.xml
   <string-array name="ImageList">
        <item>image1</item>
        <item>image2</item>
        <item>image3</item>
</string-array>
//mainactivity.java
public void onClick(View v) {
		switch(v.getId()){
	    case R.id.btnNext:
	    	String[] ImageList = getResources().getStringArray(R.array.ImageList);
	    	if(iLoopCount == ImageList.length)
	    	{
	    		iLoopCount=0;
	    	}
	    	iLoopCount = iLoopCount+1;
	    	String imagename = ImageList[iLoopCount];
	    	Toast.makeText(getApplicationContext(),imagename , Toast.LENGTH_SHORT).show();
	    	ImageView imageView1 = (ImageView) findViewById(R.id.imageView1);

	    	int drawableID = getResources().getIdentifier("drawableName", "drawable", getPackageName());
	    	Toast.makeText(getApplicationContext(),drawableID , Toast.LENGTH_SHORT).show();
	    	imageView1.setImageResource(drawableID);
	    	//imageView1.setImageResource(drawableID);
	    	break;
	    	
	    }
Thanks in Advance.
Regards,
Mahe
Posted

Hi,

Below is a pointer for you to start:-

Use the Android's AsyncTask to load images asynchronously. Something like this below; this is from the link: http://developer.android.com/reference/android/os/AsyncTask.html[^]
 
Share this answer
 
I suppose that you're getting the drawable ID right. Have you tried
Java
imageView1.setImageDrawable(drawableID);
?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900