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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:24:28+00:00 2026-06-05T03:24:28+00:00

I’m a beginner in Android development. In my project, I created a TableLayout –I

  • 0

I’m a beginner in Android development. In my project, I created a TableLayout –I reckon that a GridLayout can do more help, but since I’m not familiar with GridLayout TableLayout was taken — with some EditTexts to get values from user. The activity actually is a submit-able form. To left of each EditText, there is a TextView defining what is expected from the corresponding EditText, so I don’t have to and didn’t set a default text for EditText (which usually is used as a hint). There is also a button in this activity for submitting this form. I picked some EditTexts as MUST_FILLED ones, so in the button’s custom listener class, I have to check if these MUST_FILLEDs have been filled. follow the intuition I coded as follow:

String s4 = machine_id.getText().toString().trim();
if(s4 == null || s4 == ""){
    Toast.makeText(v.getContext(), 
            "Please Input the machine ID", Toast.LENGTH_SHORT).show();
}

machine_id here is android:id for an EditText. This code ends up with no toast displayed. So I think there is a default text value for EditText even though android:text is not defined manually. Then I wrote a simple project to confirm my thought. Here is the MainActivity.java

public class EditText_testActivity extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
private String text;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        EditText et = (EditText)findViewById(R.id.et01);
        text = et.getText().toString();

        Button btn = (Button)findViewById(R.id.btn01);
        btn.setOnClickListener(this);
    }

@Override
public void onClick(View v) {
    if(text != null)
        Toast.makeText(v.getContext(), text, Toast.LENGTH_SHORT).show();
    else
        Toast.makeText(v.getContext(), "null", Toast.LENGTH_SHORT).show();

}
}

And main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/et01" />
    <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:id="@+id/btn01"
        android:text="TouchMe"/>

</LinearLayout>

It does proved EditText has a default text value, because Toast.makeText(v.getContext(), text, Toast.LENGTH_SHORT).show(); does show a toast. However, it shows something that looks like a blank space but not exactly is.

Finally, I’m wondering what is the default value of android:text in EditText.

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-05T03:24:30+00:00Added an answer on June 5, 2026 at 3:24 am

    I believe the default value is an empty string. It will never be null because if that’s the case, you should already have encountered a NullPointerException at this line:

    String s4 = machine_id.getText().toString().trim();
    

    Looking at your code, the reason why the toast did not show up is because you used (s4 == null || s4 == "") as your if condition. == operator is different from .equals().
    Try changing your condition to "".equals(s4) instead.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

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.