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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:47:26+00:00 2026-06-06T05:47:26+00:00

In my android application I want to solve the following scenario. class Login extends

  • 0

In my android application I want to solve the following scenario.

class Login extends Activity {
   @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
         LayoutBuilder  objLB=new LayoutBuilder(this);
         objLB.createSpinner();
    } 

    public void spinnerItemSelectedEvent(AdapterView<?> parent, View view,
        int pos, long id)
    {
    }
}



class LayoutBuilder {
    private Activity objActivity;

    public LayoutBuilder(Activity a) {
        objActivity = a; 
    }

    public void createSpinner() {
        final Spinner objSPItem = new Spinner(objActivity);
        objSPItem.setOnItemSelectedListener(
            new Spinner.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id)
                {
                    // Do some common activity 
                    objActivity.spinnerItemSelectedEvent(parent,view,pos,id);
                    // calling this for do some additional task
                }
                public void onNothingSelected(AdapterView<?> arg0) {}
        });
        objActivity.spinnerItemSelectedEvent()
    }
}

and the problem is when i try to access spinnerItemSelectedEvent(parent,view,pos,id) from the ‘onItemSelected’ listner inside createSpinner method
I got the following error.

The method spinnerItemSelectedListener(AdapterView, View, int, long) is undefined for the type Activity

but out side the listner the access to the method works ok(neglect parameter list). What is the reason behind that? is any alternate way exist for solving this? plz help

  • 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-06T05:47:28+00:00Added an answer on June 6, 2026 at 5:47 am

    Activity in android represents a screen. You are making a variable objActivity of type Activity whereas it should be of type Login where the function spinnerItemSelectedEvent() is declared. Change the following lines:

    private Activity  objActivity;
    

    to

    private Login  objActivity;
    

    and your code should run.

    EDIT

    Have a BaseActivity and let all your other activities extend this BaseActivity. To make the function spinnerItemSelectedEvent() reusable declare it in the BaseActivity and you can use it the way you are trying to do it now.

    Example:

    class BaseActivity extends Activity{
        public void spinnerItemSelectedEvent(AdapterView<?> parent, View view,
        int pos, long id){ }
    } 
    
      class Login extends BaseActivity{
       public void spinnerItemSelectedEvent(AdapterView<?> parent, View view,
        int pos, long id){ //Local implementation of the function}
    }
    
    class LayoutBuilder {
    private BaseActivity objActivity;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a Android application I want to use Scanner class to read a list
I'm writing an Android application that I want to be able to send requests
I am writting an android application and i want to display a webpage inside
I am working in an android application and I want to implement a Gallery.
I want to make an android application that shows a listing of applications (downloaded
I want to pause my android application when the phone receives an incoming call.
I have been developing Android application for Android 3.x and now I want to
I developed one simple android application targeting the Mobiles with android 2.0 OS.I want
I want to implement PDF viewer in my Android application. My application has option
I want to make some changes to the stock Mms Android application and install

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.