以下代碼來自Android開發人員指南,用於在以下URL中構建相機。請花點時間幫助我解決這個問題。最好的祝願! The aforementioned site如何在Android Studio項目中實現以下OnClick代碼?
的誤差似乎是:
- 我ID之前手動添加ř...
- setOnclickListener,setCaptureButtonText,視圖V,@覆蓋和mMediaRecorder被示出爲錯誤。
- )最後被突出顯示爲錯誤。
這是從activity.xml文件,顯示該按鈕被引用的代碼:
<Button
android:id="@+id/button_capture"
android:text="Capture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
和下面的代碼本身:
private boolean isRecording = false;
// Add a listener to the Capture button
Button captureButton = (Button) findViewById(id.button_capture);
captureButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isRecording) {
// stop recording and release camera
mMediaRecorder.stop(); // stop the recording
releaseMediaRecorder(); // release the MediaRecorder object
mCamera.lock(); // take camera access back from MediaRecorder
// inform the user that recording has stopped
setCaptureButtonText("Capture");
isRecording = false;
} else {
// initialize video camera
if (prepareVideoRecorder()) {
// Camera is available and unlocked, MediaRecorder is prepared,
// now you can start recording
mMediaRecorder.start();
// inform the user that recording has started
setCaptureButtonText("Stop");
isRecording = true;
} else {
// prepare didn't work, release the camera
releaseMediaRecorder();
// inform user
}
}
}
}
);
他們沒有在那個教程中提供完整的代碼,所有那些方法都沒有在那裏提供 –