android onclick方法想要图像路径
我在我的应用程序中显示来自网络的图像。 它运行完美
我的问题是:
当我单击图像时获取当前图像 URL 的方法、函数是什么? (我将 url 作为字符串传递以进行显示)。
我使用了这种方法:
private String getAnImageUrl() {
i++;
if(i >= images.length){
i = 0;
}
public class ImageExampleXML extends Activity {
private String reviewImageLink;
private final String images[] = {"http://clients..../britney.jpg",
"http://client...../evala.jpg",
"http://clients.......ashlee.jpg",
"http://clients.......mple_1.jpg",
};
private int i = 0;
private String imgUrl;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button loadImage = (Button) findViewById(R.id.button);
final LoaderImageView image = (LoaderImageView) findViewById(R.id.loaderImageView);
loadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
image.setImageDrawable(getAnImageUrl());
}
});
image.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
imgUrl = getAnImageUrl();
Toast.makeText(getApplicationContext(), imgUrl+ " this one", Toast.LENGTH_LONG).show();
// TODO Auto-generated method stub
}
});
return images[i];
}
我通过按钮更改图像。 当我下次点击时会出现问题,它会更改 URL 但图像保持不变。
请参阅 getAnImageUrl() 导致的 onclick 中的 image.setOnClickListener 方法;
单击时我更改了显示名称.. 请告诉我如何找到当前图像网址...
注意:我使用吐司只是为了检查我得到了什么?
提前致谢。
I display image from the web in my application.
It is running perfectly
My Question is :
what is method,function to take current image URL when I click on image.?
(I passed url as string for display).
I used this method:
private String getAnImageUrl() {
i++;
if(i >= images.length){
i = 0;
}
public class ImageExampleXML extends Activity {
private String reviewImageLink;
private final String images[] = {"http://clients..../britney.jpg",
"http://client...../evala.jpg",
"http://clients.......ashlee.jpg",
"http://clients.......mple_1.jpg",
};
private int i = 0;
private String imgUrl;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button loadImage = (Button) findViewById(R.id.button);
final LoaderImageView image = (LoaderImageView) findViewById(R.id.loaderImageView);
loadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
image.setImageDrawable(getAnImageUrl());
}
});
image.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
imgUrl = getAnImageUrl();
Toast.makeText(getApplicationContext(), imgUrl+ " this one", Toast.LENGTH_LONG).show();
// TODO Auto-generated method stub
}
});
return images[i];
}
I changed image through the button.
there is problem when I clicked next time it will change URL but image remain same.
please see the method image.setOnClickListener in that onclick due to getAnImageUrl();
i changed the display name when clicked ..
please tell me how I can find current image url...
Note: I used toast only to check what i got ?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以做的就是
或者你也可以 User setTag(Object object);查看方法,例如
如果您仍然遇到图像未更改的问题。然后请分享您的LoaderImageView.java代码作为图像请求,更新是在其中处理的。
Simply what you can do is
Or you can also User setTag(Object object); method of view e.g
And If you still have problem that image is not change. Then Please share your code of LoaderImageView.java as the image request , update is handled in that.