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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:57:43+00:00 2026-06-05T11:57:43+00:00

So I guess It was a simple as using a getText() to retrieve the

  • 0

So I guess It was a simple as using a getText() to retrieve the information 🙂

Here is how it ended:

public void getToast(View v) {
    EditText et = (EditText) findViewById(R.id.userText);
    String toastText = et.getText().toString();
    if (toastText == "" || toastText == null) {
        Toast.makeText(this, "This is a nice toast!", Toast.LENGTH_SHORT).show();   
    }
    else {
    Toast.makeText(this, toastText, Toast.LENGTH_SHORT).show();
    }
}

I have created an EditText View on the main layout file. This is referenced to with the userText identifier. As it is an EditText field, the user is able to modify the text within it at any moment; what I am trying to accomplish is to retrieve the text the user has entered at the moment they tap on the button identified as getToast, and then display it as a Toast.

I am using the Resources class at the moment (my first guess?) to retrieve the String stored under toastText but this is useless, as it is extracting the text stored in the main.xml – which is empty, as I declared no “android:text” attribute for that view, instead I used an “android:hint” to tell the user to enter the text.

I had read about intents, but that kind of makes sense if I was to send the String to another activity, not within the same one. I had thought of it as a simple task, but it is consuming more time that I had hope 😛

BTW:

The getToast method is defined as an “android:OnClickMethod” for a button created on the XML. It will work with any other string of text.

Any ideas?

package com.testlabs.one;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

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

public void getToast(View v) {
    Resources myResources = getResources();
    String toastText = myResources.getString(R.string.toast); 
    if (toastText == "" || toastText == null) {
        Toast.makeText(this, "This is a nice toast!", Toast.LENGTH_SHORT).show();   
    }
    else {
    Toast.makeText(this, toastText, Toast.LENGTH_SHORT).show();
    }
}
}
  • 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-05T11:57:46+00:00Added an answer on June 5, 2026 at 11:57 am

    You simply call the function getText() on the TextView.

    Example:

    public void getToast( View v )
    {
        String toastText = ( (EditText)v ).getText();
        if ( toastText.length() == 0 ) {
            toastText = getResources().getString( R.string.toast );
        }
        Toast.makeText( this, toastText, Toast.LENGTH_SHORT ).show();
    }
    

    This code will display a toast with the text in your EditText when it is available and the default text in the toast resource when nothing was entered.

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

Sidebar

Related Questions

I guess there will be a very simple answer to this. But here goes.
A little stuck here. I have a simple question I guess. Given the following
I'm new at C#, but I guess I'm using a simple command in Directory.CreateDirectory,
I'm currently using a simple XML file that contains license information along with the
I guess this is simple, but i couldnot figure it out. i have a
I guess this is a simple question. I need to do something like this:
Simple question I guess, I want to use PHP to write an update to
I guess this is fairly simple for you but i cant wrap my head
A fairly simple question for which I have a guess, but I can't find
This is a simple question,I guess, but I couldn't figure it out. How do

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.