点击..我觉得阙很清楚请帮助我,我是android和java的新人请帮助我。
**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);
}
}
答案 0 :(得分:1)
如果String
数组中的imageList
值代表资源名称,
private String[] imageList = { "image_wo_lbl_0", "image_wo_lbl_1", "image_wo_lbl_2" };
然后您可以修改loadImage
方法:
private void loadImage(final String imagePath)
{
imageLoader.setImageResource(getResources().
getIdentifier(imagePath, "drawable", "your.application.package"));
}
如果您将网址存储在imageList
数组
private String[] imageList = { "file:///somedir/IMAG0001.jpg",
"file:///otherdir/IMAG0002.jpg",
"file:///somedir/IMAG0003.jpg" };
你可以使用
private void loadImage(final String imagePath)
{
imageLoader.setImageURI(Uri.parse(imagePath));
}
从网络加载图片时(将其网址存储在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);
}
}
为此,请不要忘记在`androidManifest.xml中为您的应用添加 android.permission.INTERNET
权限!
答案 1 :(得分:1)
@rekaszeru我用过 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);
}
答案 2 :(得分:0)
您应该只使用一个Imageview并使用setImageResource属性设置图像,并在单击下一个按钮时增加计数器值。 您还可以使用imageswitcher控件来解决此问题。
答案 3 :(得分:0)
您可以参考this SO question.每次按下时都必须调用该方法并通过传递数组中的下一个元素来更改URL。