Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5988029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:54:03+00:00 2026-05-22T22:54:03+00:00

I have camera preview on my android app but when I add an ‘id’

  • 0

I have camera preview on my android app but when I add an ‘id’ to the TextView in the xml then the app no longer runs. Are you not allowed to have a textview with an id? I need this because I would like the text to change on screen while having the camera preview?

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"  
android:layout_width="fill_parent"  
android:layout_height="fill_parent"
 > 
<SurfaceView   android:id="@+id/camerapreview"  
android:layout_width="fill_parent"  
android:layout_height="wrap_content"  
/> 
</LinearLayout>

control.xml

<?xml version="1.0" encoding="utf-8"?>

    <ImageView android:src="@drawable/icon" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_gravity="center"
        android:paddingTop="120dp" />
    <TextView android:layout_width="wrap_content" android:id="@+id/mind" 
        android:layout_height="wrap_content" android:text="First Text"
        android:layout_gravity="center" android:paddingTop="50dp"
        android:textSize="30dp" android:textStyle="bold" android:textColor="#FFFFFF" />
    <Button android:id="@+id/takepicture" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Save Image"
        android:layout_gravity="center" android:paddingTop="10dp"/>
</LinearLayout>

main.java:

package com.example.androidcamera;

import java.io.IOException;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.TextView;

public class main extends Activity implements SurfaceHolder.Callback {

Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean previewing = false;
LayoutInflater controlInflater = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    getWindow().setFormat(PixelFormat.UNKNOWN);
    surfaceView = (SurfaceView) findViewById(R.id.camerapreview);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    controlInflater = LayoutInflater.from(getBaseContext());
    View viewControl = controlInflater.inflate(R.layout.control, null);
    LayoutParams layoutParamsControl = new LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    this.addContentView(viewControl, layoutParamsControl);

    TextView textGenerateDesc = (TextView) findViewById(R.id.mind);
    textGenerateDesc.setText("hi");

    Button buttonTakePicture = (Button) findViewById(R.id.takepicture);
    buttonTakePicture.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            camera.takePicture(myShutterCallback,    myPictureCallback_RAW,
                    myPictureCallback_JPG);
        }
    });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:54:04+00:00Added an answer on May 22, 2026 at 10:54 pm

    as I can see in the xml you give the textview id as “textview” and in code you take it by R.id.mind

    Did you changed the code here or its the code that you have?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tested my application on the Android SDK on everything from 1.5 to
I have included the camera functionality in my application. I have also launched the
I was wondering whether it is possible to have 2 instances of the camera
I am attempting to build an augmented reality application for Android and have come
I am using a Preview to display what the camera see's on the screen.
I'm currently developing an app that has a camera functionality, with a custom camera
Have read the books and hints, got rid of all compile errors and warnings
I'm a student and I am developing on Android 2.2 for a project. For
I have followed this example. However, when I port it to my phone (in
I need a little help with getting my camera to work right. What I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.