单击事件不会传播到子视图
我有一个活动 A1,它有多个视图
,另一个类 ViewGenerator 有一个通过方法 getView() 返回视图的方法,
我通过为 A1 创建一个对象并调用 getView 来调用此方法。 我的班级运转良好,我能够看到风景。但是该视图的任何子视图都不可单击,因此不会在该子视图上触发单击事件。
这里是A1的getView方法,
public View getView(Main ctx) {
return getArticleView();
}
这里是getArticleView
private View getArticleView(Main ctx) {
LayoutInflater lft = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout lin = (RelativeLayout) lft.inflate(
R.layout.article_view, null);
RelativeLayout articleView = (RelativeLayout) lin
.findViewById(R.id.article_view);
summaryStuff(ctx);
return articleView;
}
,这里是summaryStuff
private void sharingStuff(final Main ctx) {
LayoutInflater lft = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout lin = (RelativeLayout) lft.inflate(R.layout.summary_bar,
null);
bookmarkRibbon = (ImageView) lin.findViewById(R.id.bookmark_selector);
bookmarkRibbon.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
bookmarkRibbon.setImageResource(R.drawable.bookmark_yellow);
}
});
}
,你可以看到bookmarkRibbon有一个监听器。但是它不可点击,或者至少没有触发事件
get View 是从 Activity 的 onCreate 方法调用的
I have an activity A1 which has several views
and another class ViewGenerator which has a method that returns a view via method getView()
I call this method by creating an object for A1 and calling getView.
my class is working fine and I am able to get the view. however any child of that view is not clickable, click event is not fired on that child.
here is A1's getView method
public View getView(Main ctx) {
return getArticleView();
}
here is getArticleView
private View getArticleView(Main ctx) {
LayoutInflater lft = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout lin = (RelativeLayout) lft.inflate(
R.layout.article_view, null);
RelativeLayout articleView = (RelativeLayout) lin
.findViewById(R.id.article_view);
summaryStuff(ctx);
return articleView;
}
here is summaryStuff
private void sharingStuff(final Main ctx) {
LayoutInflater lft = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout lin = (RelativeLayout) lft.inflate(R.layout.summary_bar,
null);
bookmarkRibbon = (ImageView) lin.findViewById(R.id.bookmark_selector);
bookmarkRibbon.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
bookmarkRibbon.setImageResource(R.drawable.bookmark_yellow);
}
});
}
as you can see bookmarkRibbon has a listener. however it is not clickable or at least the event is not fired
get View is called from Activity's onCreate method
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ImageView默认是不可点击的,即无法注册点击事件。
确保
在引用 imageview 后立即将其设置为可点击。
ImageView, by default are not clickable, i:e cannot register click events.
make sure you set The imageview clickable
right after referencing it.