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

  • Home
  • SEARCH
  • 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 8910969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:49:41+00:00 2026-06-15T03:49:41+00:00

I have the following MainActivity.java file currently running on Eclipse. My intention is to

  • 0

I have the following MainActivity.java file currently running on Eclipse.

My intention is to get the user input and the spinner value and form a url like www.ex.com?title=(user_inpu)&title_type=(spinner_input).

As of now I am hung on this part. How do I get the text value from EditText and Spinner?

I have tried writing this code:

package com.example.myfirstapp;

import org.apache.commons.logging.Log;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class MainActivity extends Activity {

Button btn;
EditText edit;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn = (Button) findViewById(R.id.button);
    edit = (EditText) findViewById(R.id.edit_message);

    btn.setOnClickListener(
            new View.OnClickListener()
            {
                public void onClick(View view)
                {
                    Log.v("EditText", edit.getText().toString());
                }
            });


Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.title_type,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        Object item = parent.getItemAtPosition(pos);
    }
    public void onNothingSelected(AdapterView<?> parent) {
    }
});

}


}

I am getting a small error:

The method v(string, String) is undefined for MainActivity.java.

I have tried replacing the Log.v("EditText", edit.getText().toString()); to Log.v("EditText", MainActivity.this.edit.getText().toString());, but the error still persists.

How do I get rid of that? And in general, will this code work?

  • 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-15T03:49:42+00:00Added an answer on June 15, 2026 at 3:49 am

    You’re not importing the right Log class.

    Just replace

    import org.apache.commons.logging.Log;
    

    by

    import android.util.Log;
    

    And you probably want to make your spinner a member of the activity (just like the button and the text field) so that you can access it from any listener.

    I mean:

    public class MainActivity extends Activity {
    
        private Button btn;
        private EditText edit;
        private Spinner spinner;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.layout_main);
    
            btn = (Button) findViewById(R.id.button);
            edit = (EditText) findViewById(R.id.edit_message);
            spinner = (Spinner) findViewById(R.id.spinner);
    
            btn.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Log.v("EditText", edit.getText().toString());
                    Log.v("Spinner", spinner.getSelectedItem().toString());
                }
            });
    
            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.title_type, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adapter);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following (simplified) code in my android MainActivity.java class case R.id.menu_stop: stopPlaying();
Hello I want to get Accurate location so that i have used following link
I have the following class: public class MainActivity extends Activity { /** Called when
I've start now in Java / Android, and I have this error... Following this
I am new to NDK. I have a cpp file which has the following
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
In my app i have an activity(MainActivity.java) and a class(non-activity class - SubClass.java). The
I have the following code in one of my apps. I get a runtime
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have following source. In insertMessage(..), it calls selectMessage to check whether duplicate record

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.