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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:58:24+00:00 2026-06-02T22:58:24+00:00

package walmart.namespace; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;

  • 0
   package walmart.namespace;

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

import android.widget.EditText;
import android.widget.TextView;

public class WalmartActivity extends Activity {
        /** Called when the activity is first created. */

        EditText name;
        Button search;
    TextView display;

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

                name = (EditText)findViewById(R.id.etName);

                search = (Button) findViewById(R.id.btnSearch);

                display = (TextView) findViewById(R.id.tvdisplay);



                name.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                                name.setText("");
                        }
                });
                search.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                               if (name.equals("Electronics")) {
                                display.setText ('5');
                           } else if (name.equals("candy")) {
                                   display.setText ('1');
                           } else if (name.equals("Tobacco")) {
                               display.setText ("1");
                           } 
        }});
};}

No matter what i do, nothing shows up in my output. I’m very, very new to JAVA, so I can’t seem to find out why nothing’s showing up on my display.

edit Edited my code to what i currently have. Still not working.

  • 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-02T22:58:25+00:00Added an answer on June 2, 2026 at 10:58 pm

    Looking at that code, the issue might be with how you are initializing name and search.

    Change your code:

    name = (EditText) findViewById(getResources().getIdentifier("etName", "id", getPackageName()));
    search = (Button) findViewById(getResources().getIdentifier("btnSearch", "id", getPackageName()));
    

    to this:

    name = (EditText) findViewById(R.id.etName);
    search = (Button) findViewById(R.id.btnSearch);
    

    Also, add a TextView to display your answer into your main.xml file, give it an id (let’s say display for example) android:id="@+id/display" and then add it to your activity so you can change it:

    display = (TextView) findViewById(R.id.display);
    

    and then you can update it by calling:

    display.setText('some text');
    

    Thus the start of your file should look like this:

    public class WalmartActivity extends Activity {
        /** Called when the activity is first created. */
    
        EditText name;
        Button search;
        TextView display;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main); 
    
            name = (EditText) findViewById(R.id.etName);
            search = (Button) findViewById(R.id.btnSearch);
            display = (TextView) findViewById(R.id.display);
    
            ....
    

    Next update your if statements from:

    if (name.equals("Electronics"))
    

    to:

    if (name.getText().toString().equals("Electronics")) {
        display.setText("something");
    }
    

    An example piece of code:

    Demo2Activity.java

    package com.demo1;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    public class Demo2Activity extends Activity {
        private Button button;
        private EditText editText;
        private TextView textView;
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main2);
            button = (Button) findViewById(R.id.button);
            editText = (EditText) findViewById(R.id.editText);
            textView = (TextView) findViewById(R.id.textText);
    
            button.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    if (editText.getText().toString().equals("Electronics")) {
                        textView.setText("found");
                    }
    
                }
            });
    
        }
    }
    

    main2.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="main2.xml"
            android:id="@+id/textText" />
        <EditText 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/editText"/>
        <Button
            android:id="@+id/button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="button" />
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package com.parseador.prueba; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class main extends
package com.example.android.home; import android.app.Activity; import android.os.Bundle; import android.widget.*; import android.view.*; public class HomeActivity extends
package com.commonsware.android.layouts; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import java.util.Date; public class
package com.rest; import java.io.IOException; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button;
package nidhin.survey; import android.app.Activity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.*;
package com.duncan.hello.world; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;
package com.RaffDev.RaffApp; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.View; import android.widget.Toast; import android.widget.AdapterView;
package com.comboyz.TantaGo; import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; public class startMenu extends ListActivity{ @Override
package woot.wat.wen; import android.app.Activity; import android.os.Bundle; import android.text.Layout; import android.util.Log; import android.view.KeyEvent; import android.view.View;
package com.ustr.eMIRnew; import java.util.ArrayList; import java.util.HashMap; import android.R; import android.app.Activity; import android.os.Bundle; import android.widget.ListView;

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.