许多照片安卓工作室的Onclick事件 [英] Onclick event on many pics android studio

查看:113
本文介绍了许多照片安卓工作室的Onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是android studio的初学者。

在一个应用程序中有五个水平行。在任何一行中都有pic的十个图片和属性。点击任意图片,将额外的意图投射到另一个活动。

如何为所有图片编写onclick事件?

我应该为所有图片编写50个onclick事件吗?

还有其他方法吗?

谢谢



我的尝试:



Android工作室中任何图片的相同点击功能

Hello, I am a beginner in android studio.
In an application there is five horizontal rows. In any row there are ten pics and properties of the pic. Click on any pic put extra to intent and direct to another activity.
How can I write onclick event for all pics?
Should I write 50 onclick events for all pics?
Is there any other way?
Thanks

What I have tried:

Same click function for any pic in android studio

推荐答案

我在活动中写了一个方法,说



I'd write a method in the Activity, say

public void onImageClick(View view) {
    ImageView image = (ImageView)view;
    // ... do your stuff with the image, add your extra to intent, etc etc
}





在xml设计中我只想把





and in the xml design I'd simply put

android:onClick="onImageClick"


每个ImageView中的


。 />


当然,这可以进行优化(创建一个包含完全格式化的图像视图的xml设计,就像你需要的那样,只需< include>那个imageview 50次或派生你的拥有ImageView等,但正如你所说,你是Android Studio的初学者,我会在这里采用最简单的方法让你掌控正在发生的事情。



in every ImageView.

Of course, this can be optimized (creating a xml-design containing a fully formatted imageview the way you need it and simply <include> that imageview 50 times or derive your own ImageView etc, but as you said, you are a beginner in Android Studio, I'd go for the most simple approach here so you keep control of what's happening.


这篇关于许多照片安卓工作室的Onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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