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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:59:58+00:00 2026-05-25T12:59:58+00:00

This is my onCreate function. Since there is lot of code inside onclickListener for

  • 0

This is my onCreate function.

Since there is lot of code inside onclickListener for Hello i want to shift it outside to a method. how can i do that ?

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        facebook.authorize(this, permissions, Facebook.FORCE_DIALOG_AUTH,
                new DialogListener() {

                    public void onComplete(Bundle values) {
                    }

                    public void onFacebookError(FacebookError error) {
                    }

                    public void onError(DialogError e) {
                    }

                    public void onCancel() {

                    }
                });

        hello = (Button) findViewById(R.id.hello);
        info = (TextView) findViewById(R.id.facebook_info);
        content = (TextView) findViewById(R.id.content);

        hello.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                // bundle.putString("fields", "email");
                try {
                    about = facebook.request("me");
                    json = Util.parseJson(about);
                    id = json.getString("id");
                    first_name = json.getString("first_name");
                    last_name = json.getString("last_name");
                    email = json.getString("email");

                    if (!json.isNull("username")) {
                        username = json.getString("username");
                    } else {
                        Log.d("TAG", "Username not set");
                    }

                    dob = json.getString("birthday");
                    gender = json.getString("gender");
                    location = json.getString("location");

                    json_location = Util.parseJson(location);
                    place = json_location.getString("name");

                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (FacebookError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                // info.setText(about);
                content.setText(id + " \n" + first_name + " \n" + last_name
                        + " \n" + email + " \n" + username + " \n" + dob
                        + " \n" + gender + " \n" + place);
            }
        });

    }
  • 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-25T12:59:58+00:00Added an answer on May 25, 2026 at 12:59 pm

    Create an inner class extending OnClickListener.

    private class MyOnClickListener implements OnClickListener { ... }
    

    In here you add the exact same implementation as you all ready have for the anonymous OnClickListener. Just make sure that all variables you access are declared as local variables in your Activity-class.

    Then when you set the onClickListener you just do this:

    hello.setOnClickListener( new MyOnCLickListener() );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity that extends MapActivity, and inside onCreate() I have this code
I have code like this public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); boolean autoLogin
This is a bit of a long shot, but if anyone can figure it
The following code executes a function that retrieves a file via ftp and then
I am having issues with storing JSON data to sqlite. This is the code
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); Main(); }
I'm using this code snippet to encrypt/decrypt data in my app's database: http://www.androidsnippets.com/encryptdecrypt-strings It
This bug tricked me into spending 4 hours debugging perfectly functional code last night.
This is probably a trivial question for experienced devs, but since I'm comming from
I have to understand this code to create my own app(almost based on 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.