How do I make individual childs of ViewGroup clickable in android java?

28 views Asked by At

I have an android java application and I have a ViewGroup in it. I'm adding CustomCircleViews to the ViewGroup. I want to add onClickListener on each CustomCircleView added to the view group. Here is how I'm doing it.

ViewGroup viewGroup = binding.viewContainer;
CustomCircleView ccv = new CustomCircleView();
ccv.setOnClickListener(v->(){AlertDialog code});
viewGroup.add(ccv);
viewGroup.add(ccv2);
.
.
. and so on...

Now what is happening is that whenever I'm clicking anywhere on the view group the alert dialog is triggered, which i dont want and also only the onClickListener of last CustomCircleView is being shown.

My xml code...

<FrameLayout
  
all the necessary things added

/>

I tried adding setDescentantFocusability() to all the three options focus after, focus before, focus block. But it is not working.

Any idea how can I make my app to show alert dialog only when I click on CustomCircleViews added to the viewGroup. and also to include all onClickListeners.

0

There are 0 answers