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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:43:48+00:00 2026-06-04T21:43:48+00:00

just for learning purpose <Button android:id=@+id/button android:text= android:layout_width=fill_parent android:layout_height=fill_parent android:onClick=updateTime/> public class MainActivity extends

  • 0

just for learning purpose

<Button 
android:id="@+id/button"
android:text=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="updateTime"/>


public class MainActivity extends Activity {
Button btn;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    btn = (Button) findViewById(R.id.button);
    updateTime(btn);

}

public void updateTime(View b) {
    btn.setText(new Date().toString());
}

}

if View b it’s a reference to btn how can pass it

as View ?
I’ve tried like

public void updateTime(Button b) {
    b.setText(new Date().toString());
}

but it doesn’t work
Can you help me, please?

Thanks in advance.

  • 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-04T21:43:50+00:00Added an answer on June 4, 2026 at 9:43 pm

    Have you tried:

    public void updateTime(View b) {
        ((Button)b).setText(new Date().toString());
    }
    

    From the documentation:

    This name must correspond to a public method that takes exactly one
    parameter of type View

    So if you are defining updateTime as a click action listener in the xml layout, then your callback must match the signature public void updateTime(View v), which means you can’t declare it as accepting a Button as an argument.

    Also, android:onClick only works for API level 4 and up, so if you’re targeting API levels below that, you will have to declare the click action listener in code..

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

Sidebar

Related Questions

I have this class, just for the purpose of learning: public class MyClass{ //Looking
I'm just learning PHP, and I'm confused about what the purpose of the __construct()
Just want to look at how things are implemented for learning purpose and may
Just learning how to work with php and mysql, using CodeIgniter. Running into that
Just learning Silverlight 4/RIA and i 'm stuck in a weird problem: setup an
Just learning C#, radiobuttons and checkboxes. No urgency. The code works to display the
Im just learning mod_rewrite and regex stuff, and what I'm trying to do is
Im just learning SQLite and I can't get my parameters to compile into the
I'm just learning java out of a what seems to be an excellent book,
I'm just learning jQuery, I'm so noob. see, we have 2 divs as follows:

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.