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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:55:33+00:00 2026-06-07T00:55:33+00:00

Below is my main activity file. I am stuck with the bottom area (commented

  • 0

Below is my main activity file. I am stuck with the bottom area (commented out). I want to make it so that when I hit button b1, the text changes from what it is for default. So say it says “hello” by default, I want to switch the text to something like “how are you” when you press button b1. I have tried many things, but I always get errors. Can someone help me?

package com.wdmc85.donottouch;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class DoNotTouchActivity extends Activity 
implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button b1 = (Button) this.findViewById(R.id.b1);
    b1.setOnClickListener(this);


}

@Override
public void onClick(View v) 
{
    switch(v.getId())
    {
    case R.id.b1:
        //WHAT DO I PUT IN HERE?? I WANT IT SO WHEN YOU HIT BUTTON B1, THE 
        //TEXT CHANGES FROM WHAT IT IS FOR DEFAULT. SO SAY IT SAYS "HELLO"
        //AS DEFAULT, HOW DO I MAKE IT SO WHEN YOU PRESS BUTTON B1 THE TEXT
        //CHANGES FROM "HELLO" TO "HOW ARE YOU?" I HAVE TRIED ALL SORTS OF
        //THINGS BUT NOTHING HAS WORKED
    break;
    }

}

}

  • 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-07T00:55:34+00:00Added an answer on June 7, 2026 at 12:55 am

    if want to change text of the button itself

     switch(v.getId())
            {
            case R.id.b1:
               Button b1 = (Button) v;
               b1.setText("HOW ARE YOU?");
    
            break;
            }
    

    if want to change text of the any other Textview

     switch(v.getId())
            {
            case R.id.b1:
               TextView tv = (TextView ) this.findViewById(R.id.<tvid>);
               tv .setText("HOW ARE YOU?");
    
            break;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing an app that within a certain activity, we want the
I have an activity that sets xml by calling the below xml. This xml
I wrote an android program that: has a main activity for UI, and it
I am making an app in which i have a main activity that the
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
(In short: main()'s WaitForSingleObject hangs in the program below). I'm trying to write a
Please check below screen shot. What is main difference between Master Page and MVC
I have a code like this below in /root_project/main.cpp : #include theoraplayer/TheoraVideoClip.h unsigned int
Let's consider the below example. There, I have: target MAIN calls target t and
my test code is below: main1.c: #include <stdio.h> extern struct tt ; int main()

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.