动态创建的视图不响应OnClickListener

时间:2015-03-25 22:16:08

标签: android view onclicklistener android-custom-view

我有一个名为EventListSmallViewFollowerFollowingView的视图,它扩展了RelativeLayout,并在我的活动中动态创建。

问题是: 如果我为FollowerFollowingView设置onClickListener它可以正常工作,但是当我尝试使用EventListSmallView时它不起作用。

这就是我如何设置每一个: - EventListSmallView

for (Event event : eventsGo){
            final Event e = event;
            EventListSmallView eventListSmallView = EventListSmallView_.build(this);
            eventListSmallView.bind(event);
            eventListSmallView.setClickable(true);
            eventListSmallView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String json = new Gson().toJson(e);
                    EventDetailActivity_.intent(ProfileActivity.this)
                            .extra("json", json).start();
//                    Intent it = new Intent(ProfileActivity.this, EventDetailActivity_.class);
//                    it.putExtra("json", json);
//                    startActivity(it);
                }
            });

            dynamicGo.addView(eventListSmallView);
        }

和FollowerFollowingView:

FollowerFollowingView itemView = FollowerFollowingView_.build(this);
        itemView.bind(p);
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String json = new Gson().toJson(profile);
                if (profile.getId() == Config.getMyID(getApplicationContext())){
                    ProfileActivity_.intent(EventDetailActivity.this)
                            .extra("serialized_profile", json).extra("is_user",true).start();
                }else {
                    ProfileActivity_.intent(EventDetailActivity.this)
                            .extra("serialized_profile", json)
                            .start();
                }
            }
        });
        whoGoing.addView(itemView);

0 个答案:

没有答案