Click event not propagating to child view
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 = (LayoutInflate开发者_如何学运维r) 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
ImageView, by default are not clickable, i:e cannot register click events.
make sure you set The imageview clickable
bookmarkRibbon.setClickable(true);
right after referencing it.
精彩评论