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 8043241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:50:29+00:00 2026-06-05T04:50:29+00:00

I am attempting to use some of Google’s code from their audio capture sample

  • 0

I am attempting to use some of Google’s code from their audio capture sample code. They simplified the heck out of their code and made their layout within the class. I want to have an actual xml layout. I know how to do that part, but I would like to know how to change the code below to an onClick method and have all the functionality that is provided with it.

class PlayButton extends Button {      
    boolean mStartPlaying = true;   
    OnClickListener clicker = new OnClickListener() {  
        public void onClick(View v) {          
            onPlay(mStartPlaying);            
            if (mStartPlaying) {              
                setText("Stop playing");        
            } else {              
                setText("Start playing");     
            }          
            mStartPlaying = !mStartPlaying;      
        }      
    };      

    public PlayButton(Context ctx) {   
        super(ctx);           
        setText("Start playing");      
        setOnClickListener(clicker);    
    }   
}

Any help is appreciated.

  • 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-06-05T04:50:30+00:00Added an answer on June 5, 2026 at 4:50 am

    In the layout file, you’ll have something like…

    <LinearLayout>
       <Button android:id="play_button"/>
    </LinearLayout>
    

    In the activity, onCreate(), you can then do something like..

    OnClickListener clicker = new OnClickListener() {  
        public void onClick(View v) {          
            onPlay(mStartPlaying);            
            if (mStartPlaying) {              
                setText("Stop playing");        
            } else {              
                setText("Start playing");     
            }          
            mStartPlaying = !mStartPlaying;      
        }      
    };      
    Button b = findViewById(R.id.play_button);
    b.setOnClickListener(clicker);
    

    ALTERNATELY, you can also define the method in the xml layout that will be called in the Activity…

    <LinearLayout>
       <Button android:id="play_button" onclick="play"/>
    </LinearLayout>
    

    and then in the Activity you simply create a method, called play(View view)

    public void play(View view) {
                onPlay(mStartPlaying);            
                if (mStartPlaying) {              
                    setText("Stop playing");        
                } else {              
                    setText("Start playing");     
                }          
                mStartPlaying = !mStartPlaying;      
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to write some Java code that takes an image from a
I'm attempting to use JUnit to test some database code. I'm pretty new to
I've been attempting to use the C++ stringstream class to do some relatively simple
So I'm attempting to use a queue to parse some input, turning prefix mathematical
I am attempting to use a jquery drowndown checklist control. Following some simple examples,
Attempting to use the data series from this example no longer passes the JSONLint
When attempting to use HttpWebRequest to retrieve a page from my dev server, I
In attempting to use std::select1st from <functional> in a VS2008 project I found that
I'm attempting to expose some of the Google URL Library functionality as a perl
I am attempting a GPS application and i wanted to use Google maps API

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.