如何在Android上动态添加多个ImageView

I am using two types of button. increment and decrement. I am clicking the increment button new added the imageview and decrement button click remove the imageview. i have problem is Clicking even . i added the multiple imageview only one imageview only worked another images not working. please help i attached the my code. enter image description here

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_onboarding__no__relative);
    parentlenalayout = findViewById(R.id.parentlayout);
    childlinearlayout = findViewById(R.id.childlayout);
    ButterKnife.bind(this);
    mCompressor = new FileCompressor(this);
    imgList = new ArrayList<Integer>();
    imgList.add(1);
    if (!checkPermissions()) {
        isRuntimePermission();
    }
    decbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mCount > 1) {
                decrement();
                if (parentlenalayout.getChildCount() != 1)
                    parentlenalayout.removeViewAt(parentlenalayout.getChildCount() - 1);
                imgList.remove(parentlenalayout.getChildCount() - 1);
                Log.e("imagecountremove------", ":" + imgList.size());
            } else {
                Toast.makeText(getApplicationContext(), "Not allowed", Toast.LENGTH_LONG).show();
            }
        }
    });

    incbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mCount <= 2) {
                increment();
                addlayout();

            } else {
                Toast.makeText(getApplicationContext(), "Not allowed", Toast.LENGTH_LONG).show();
            }
        }
    });


    if (savedInstanceState != null) {
        mCount = savedInstanceState.getInt("count");
        countadult.setText(String.valueOf(mCount));
    }

    for (int i = 0; i <= imgList.size(); i++) {
        Log.e("imagesize",":"+imgList.size());
        btn[i] = new ImageView(this);
        btn[i].setId(R.id.img_id_proof_photo);
        btn[i].setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    Log.d("Permissi", "" + isRuntimePermission());
                    if (!isRuntimePermission()) {
                        requestCameraPermission();
                    } else {
                        // startActivityForResult(getPickImageChooserIntent(), CERTIFICATE_SCAN_CAPTURE_IMAGE_REQUEST_CODE);
                        selectImage();

                    }

                } else {
                    // startActivityForResult(getPickImageChooserIntent(), CERTIFICATE_SCAN_CAPTURE_IMAGE_REQUEST_CODE);
                    selectImage();
                }

            }
        });
    }
}

@Override
public void onClick(View view) {

}

private void addlayout() {

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View rowview = inflater.inflate(R.layout.activity_onboarding__no__relative, null);
    LinearLayout linearLayout = rowview.findViewById(R.id.childlayout);
    ((ViewGroup) linearLayout.getParent()).removeView(linearLayout);
    parentlenalayout.addView(linearLayout, parentlenalayout.getChildCount() - 1);
    imgList.add(parentlenalayout.getChildCount());
    Log.e("imagecount", ":" + imgList.size());
}
评论