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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:53:59+00:00 2026-05-17T18:53:59+00:00

So I am a complete newb, and am currently taking an intro to Mobile

  • 0

So I am a complete newb, and am currently taking an intro to Mobile Programming course in which we use Android (I have some experience with Java). I am trying to do a simple assignment which displays a text field and an image, and upon entering the correct “password” and pressing enter, the image changes.

Should be so simple! But I am having a really hard time with this and can’t figure out what I am doing wrong, even after doing a good bit of searching (I assume it is something super obvious and I’m missing it).

Here is my code:

package CS285.Assignment1;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ImageView;

public class DisplayImage extends Activity 
      implements OnKeyListener{

 private EditText enteredText;
 private String pass = "monkey";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        enteredText = (EditText)findViewById(R.id.passField);
        enteredText.setOnKeyListener(this);    

    }

    public boolean onKey(View v, int keyCode, KeyEvent event) {

        // If the event is a key-down event on the "enter" button
        if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
            (keyCode == KeyEvent.KEYCODE_ENTER)){
          // Perform action on key press

         switchImage();

          return true;
        }
        return false;
    }

    public void switchImage(){

  if(enteredText.getText().toString() == pass){
   ImageView imgView = (ImageView)findViewById(R.id.Image);
         imgView.setImageResource(R.drawable.marmoset);
  }     
    }

}

and my main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 <TextView android:id="@+id/textPrompt" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:background="#ff993300" 
  android:text="Please enter password to see my real picture:" 
 >
 </TextView>
 <EditText android:id="@+id/passField"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
    >
        </EditText>
<ImageView 
 android:id="@+id/Image"
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:adjustViewBounds="true" 
 android:src="@drawable/airplane"
/>


</LinearLayout>

I thought at first that I was not properly extracting the String from “enteredText” so the comparison to the “password” wasn’t happening correctly, but I have since tried just printing the enteredText and it works fine.

Totally frustrated–Any help would be greatly appreciated!

Daniel

  • 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-17T18:54:00+00:00Added an answer on May 17, 2026 at 6:54 pm

    if(enteredText.getText().toString() == pass) should be if(enteredText.getText().toString().equals(pass)).

    As a stylistic matter, you should not do the checking within the switch image function – you should check that the password matches and then call the switch image function.

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

Sidebar

Related Questions

Complete new person to Ruby and Rails here... Have tried some tutorials in the
Complete prolog beginner here. Let's say I have a prolog knowledge base which contains
I'm a complete newb writing out a small little script in which the third
I am a complete newb to the RewriteRule so I'm asking for some help
I have setup Django and am a complete newb. I have successfully connected to
I am using heroku, php and javascript, I am a complete newb. I have
I'm a complete newb to C++, but not to Java, C#, JavaScript, VB. I'm
Complete beginner to Rails here: In Rails: I have a Model Post, which hasmany
Complete C# newbie here, so cut me some slack. I have this application that
I keep having problems with programs in Python (I'm a complete newb) where it

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.