Ask Your Question

How to add a button to switch between cameras

asked 2013-05-21 10:36:16 -0500

sp_mic88 gravatar image

How can I add a button to camera-control opencv4android example? I have simply added in the main.xml file:

<button android:id="@+id/imgShoot" android:text="Capture" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right"/> and in OnCreate function, in, after setContentView:

final Button button = (Button) findViewById(; button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click } }); but it doesn't work. This button should be able to switch between front and back camera, in my device.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-03-30 08:48:54 -0500

    public void swapCamera() {
            int index = CAMERA_ID_FRONT;
            if (getCameraIndex() == CAMERA_ID_FRONT)
                index = CAMERA_ID_BACK;
edit flag offensive delete link more

Question Tools


Asked: 2013-05-21 10:36:16 -0500

Seen: 1,584 times

Last updated: Mar 30 '17