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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:55:56+00:00 2026-06-13T14:55:56+00:00

I am using Intellij IDEA 11, Android 4.1 and using the example in http://www.mkyong.com/android/android-textbox-example/

  • 0

I am using Intellij IDEA 11, Android 4.1 and using the example in http://www.mkyong.com/android/android-textbox-example/ to display toast text after a user enters a text in the edit text then presses enter. The problem is that the enter key always creates a new line, the keyboard is still there and the toast is not displayed. I’m using emulator ARM with skin WVGA800 to test this if that makes any difference.

I tried diffrent things including:

edittext.requestFocus(); 
edittext.setFocusable(true);
edittext.setFocusableInTouchMode(true); and
edittext.setMaxLines(1);

but it is still not working.

Here is the xml code:

<?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"
        >

    <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

    <requestFocus />

    </EditText>

    </LinearLayout>

Here is the java code:

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.TextView;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.Toast;

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

    private EditText edittext;

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

    public void addKeyListener() {

        // get edittext component
        edittext = (EditText) findViewById(R.id.editText);

        //edittext.setFocusable(true);
        //edittext.setFocusableInTouchMode(true);
        //edittext.setMaxLines(1);

        // add a keylistener to keep track user input
        edittext.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {

                // if keydown and "enter" is pressed
                if ((event.getAction() == KeyEvent.ACTION_DOWN)
                        && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    edittext.requestFocus();
                    // display a floating message
                    Toast.makeText(T_C_Activity.this,
                            edittext.getText(), Toast.LENGTH_LONG).show();

                    return true;

                } else if ((event.getAction() == KeyEvent.ACTION_DOWN)
                        && (keyCode == KeyEvent.KEYCODE_9)) {
                    edittext.requestFocus();
                    // display a floating message
                    Toast.makeText(T_C_Activity.this,
                            "Number 9 is pressed!", Toast.LENGTH_LONG).show();
                    return true;
                }

                return false;

            }

        });

    }
}

Thanks in advance.

  • 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-13T14:55:57+00:00Added an answer on June 13, 2026 at 2:55 pm

    Take a look at the imeOptions section of the API documentation.

    For example, you could do something like this:

    <EditText
                    android:id="@+id/edit_name"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:editable="true"
                    android:singleLine="true"
                    android:imeOptions="actionGo"
                    android:focusable="true"
                    />
    

    Then, You can listen for editor events like this:

            EditText editText = (EditText) findViewById(R.id.edit_name);
            editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                    if(i == EditorInfo.IME_ACTION_GO){
                          //do whatever you want
                    }
                    return false;
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using IntelliJ IDEA 10.5.2 Example: Say I want to rename this class to
I'm using IntelliJ IDEA v11.0.1 In Run/Debug configuration of my Android application I can
I am trying to learn android app development .I am using IntelliJ Idea 10.When
I am using IntelliJ IDEA for Android development. But there is one thing annoying
I am trying to include a library into my android project using IntelliJ IDEA
IntelliJ Idea Android tutorial suggests using go to resource facility appearing as a triangle
I've been using IntelliJ IDEA 9.0 Community Edition for some time after years living
I am developing an android application using IntelliJ IDEA 11.1.2 and I need datepicker
I'm using IntelliJ IDEA to develop for Android. Now I want to introduce ProGuard.
I need android.permission.WRITE_SETTINGS for my Android application's junit tests. I am using IntelliJ Idea

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.