从Android中的res\drawable动态加载图像 [英] Loading the Image dynamically from res\drawable in Android

查看:667
本文介绍了从Android中的res\drawable动态加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



开发图片幻灯片放映应用程序。我已将所有图像添加到res\drawable-hdpi文件夹中。我想动态形成url并需要动态加载图像。



在Next Button点击事件,我需要从文件夹中加载下一个文件/>

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

//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;
	    	
	    }

先谢谢。

问候,

Mahe

Thanks in Advance.
Regards,
Mahe

推荐答案





下面是一个指针供你开始: -



使用Android的AsyncTask异步加载图像。这样的事情如下;这是来自链接: http://developer.android.com/reference/android/os/AsyncTask。 html [ ^ ]


我想你正确得到了可绘制的ID。你试过
I suppose that you're getting the drawable ID right. Have you tried
imageView1.setImageDrawable(drawableID);


这篇关于从Android中的res\drawable动态加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆