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

  • SEARCH
  • Home
  • 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 6685013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:00:29+00:00 2026-05-26T05:00:29+00:00

I have a custom SurfaceView defined in my layout xml. I can draw to

  • 0

I have a custom SurfaceView defined in my layout xml. I can draw to the canvas no problem with an associated external class which extended SurfaceView. However, my aim is to draw an initial state (lets call it state 0) to the canvas which is some text with a white background, and after some event such as a button press an image is drawn (lets call it state 1) on the same canvas. Separately I can draw both of these states to the same canvas, however I am having difficulty in changing the state of the canvas when an event occurs.

There might also be another method to do this, perhaps creating an overlaid view on top and programatically calling it on the button press.

Here are my particulars: xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#FFFFFFFF" 
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

    <TextView android:layout_height="wrap_content"
    android:layout_marginLeft= "5dp"
    android:layout_marginTop = "5dp"
    android:layout_marginBottom = "5dp"
    android:id="@+id/textNoisy" 
    android:layout_width="fill_parent"
    android:text="@string/TextNoisy"
    android:textColor="#161616"></TextView>

<com.speechenhancer.SpecGuageNoisy 
    android:id="@+id/SpecGuageNoisy"
    android:layout_width="fill_parent" 
    android:layout_height="220dp"
    android:layout_below="@+id/textNoisy"/>

<TextView android:layout_height="wrap_content" 
    android:layout_marginLeft= "5dp"
    android:layout_marginBottom = "5dp"
    android:id="@+id/textEnhanced" 
    android:layout_below="@+id/SpecGuageNoisy"
    android:layout_width="wrap_content"
    android:text="@string/TextEnhanced"
    android:textColor="#161616"></TextView>


<Button android:id="@+id/ButtonEnhance" 
    android:layout_marginTop = "20dp"
    android:layout_width="140dp"
    android:layout_height="wrap_content"
    android:text="@string/ButtonEnhance"
    android:layout_alignParentBottom="true"
    android:layout_gravity="center" ></Button>

Main Activity

public class SpecGuageNoisy extends SurfaceView implements SurfaceHolder.Callback {


 public SpecGuageNoisy(Context context, AttributeSet attributeSet) {
    super(context, attributeSet);


    holder = getHolder();
    holder.addCallback(this);

}
   @Override
public void surfaceChanged(SurfaceHolder holder, int format,
        int width, int height) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub

}
@Override
public void surfaceCreated(SurfaceHolder holder) {
    if (SpecState.getCanvasState()==0){
        // Draw Initial state
    }else if (SpecState.getCanvasState()==1){
    spectrum = init();
    canvas = getHolder().lockCanvas();
    canvas.drawColor(Color.WHITE);
    onDraw(canvas,spectrum, nsegs, seglen,nshift);
    getHolder().unlockCanvasAndPost(canvas);
    }
}

Custom SurfaceView:

public class SpecGuageNoisy extends SurfaceView implements SurfaceHolder.Callback {


 public SpecGuageNoisy(Context context, AttributeSet attributeSet) {
    super(context, attributeSet);


    holder = getHolder();
    holder.addCallback(this);

}
 @Override
public void surfaceChanged(SurfaceHolder holder, int format,
        int width, int height) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub

}
@Override
public void surfaceCreated(SurfaceHolder holder) {
    if (SpecState.getCanvasState()==0){
        // Draw Initial state
    }else if (SpecState.getCanvasState()==1){
    spectrum = init();
    canvas = getHolder().lockCanvas();
    canvas.drawColor(Color.WHITE);
    onDraw(canvas,spectrum, nsegs, seglen,nshift);
    getHolder().unlockCanvasAndPost(canvas);
    }
}
  }

In this code I have not show drawing state 0, nor an attempt to set an onlick listener on to the ButtonEnhance. I haven’t shown the onDraw function either, as it works well. I have just pasted it here to illustrate my setup. I am not getting any error’s to report logcat information. It’s more that I need some help in formulating how to achieve this particular case. Any idea’s? Thanks

  • 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-26T05:00:29+00:00Added an answer on May 26, 2026 at 5:00 am

    Try mplement thread to draw things on canvas, something like in this tutorial. It might solve your problem.

    http://www.droidnova.com/playing-with-graphics-in-android-part-iii,176.html

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

Sidebar

Related Questions

I have a custom View extending SurfaceView. The XML layout is <com.myPackage.MyCustomView android:id=@+id/mycview android:layout_width=fill_parent
I have custom type name Netsgroup which is a collection of Net class. Net
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I have custom exceptions in my django project that look like this: class CustomFooError(Exception):
I have custom cell which contains number of rows in it.i want to write
I have this simple layout: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical >
The scenario is the following: I have an activity RunTrainingWorkoutsView that uses XML layout
I have a dialog box which appears on top of a SurfaceView. I would
I have custom coded layout to hold all the childs. Here is the code:
how to clear the surfaceView in android? I have a class like this -

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.