Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Handling empty EditText with toast

You are getting an error, because your findViewById(...) isn't bound to the correct this. It should be outside of the onClick listener.

Typically, I would do something like the following:

public class MainActivity extends
Activity {

private EditText sun;
private EditText mon;
private EditText tue;
private EditText wed;
private EditText thu;
private EditText fri;
private EditText sat;
private EditText wage;

protected void onCreate(Bundle savedInstanceState)


private void instantiateViews() {

    sun  = (EditText) findViewById(;
    mon  = (EditText) findViewById(;
    tue  = (EditText) findViewById(;
    wed  = (EditText) findViewById(;
    thu  = (EditText) findViewById(;
    fri  = (EditText) findViewById(;
    sat  = (EditText) findViewById(;
    wage = (EditText) findViewById(;

//Write whatever other code you would here

Also, I recommend you use TextUtils.isEmpty over your current method to check that wage is empty.

Categories : Android

Related to : Handling empty EditText with toast
the EditText is empty and the method always returns true?
Change your if statement as follows: if (et_topic.getText().toString().trim().equals("")) EditText#getText() returns an Editable object, which won't be equal to "".

Categories : Java
Notification like Toast but with longer duration
From a quick search in SO, you can find the Toast durations: private static final int LONG_DELAY = 3500; // 3.5 seconds private static final int SHORT_DELAY = 2000; // 2 seconds Now you can display multiple Toasts one after the other to look like it has a longer duration: final String msg = "Some text"; Runnable delayedToast = new Runnable() { @Override public void run() { Toas

Categories : Java
Async Task and Toast - Android
In the your Task class, create a constructor and give it your context like this: private class Check_Loguin_Request { Context cx; public Check_Loguin_Request(Context cx) {; } } Then in the OnPostExecute use this cx protected void onPostExecute(String result) { Toast.makeText(cx, "Task Finalized: " + result, Toast.LENGTH_SHORT).show(); } The use this class like this:

Categories : Android
Need Solution : Message is not Showing Toast
Don't mix multiple Writers and OutputStreams or Readers and InputStreams on the same socket. It won't work. PrintWriter is buffered. If you write something and then expect a response you need to flush it after the write.

Categories : Android
How to show toast according to user input?
Your app crashes on the line final int Me= Integer.parseInt(a);, since your EditText will be empty in the OnCreatemethod and an empty string cannot be parsed to an integer. You should catch the NumberFormatException You should get the text in the OnClickListener, because only then you have given the user the opportunity to enter a value in the EditText. So your code will be: sub.setOnClickList

Categories : Android
Recently Add
Wait for all requests in Android Volley
android scrollview not working
Android: How to prevent a Wifi disconnect on DHCP renewal?
Using HorizontalScrollView for gallery - no pictures inside
-bash: export: not a valid identifier
m3u8 Video stops with MediaPlayer: Error (1,-1004)
java.lang.IndexOutOfBoundsException at ListView android
Facebook REST calls for mobile cross-platform app
How to returning image from camera intent and placing in google maps api v2 as thumbnail
How can I add a row to a ListView in one Fragment by clicking the button in another Fragment?
Using MediaController on Android 5
Is TCP packet filtering possible on mobile platforms?
Spinner from editext android
Incomplete file downloaded in android using DataInputStream
How do I delete a row form SQLite DB via ListView and refresh list view?
Change action bar to toolbar, and now I am having force closes. What am I doing wrong here?
Adding buttons below GraphView, all inside a Fragment
Get rotation and display in degrees
What methods are available to execute things in the background
Data Persistence Android
Intent not delivered correctly
Android Studio 1.0 RC 1 Gradle build issues - Could not run build action using Gradle installation
otto eventbus for android behaves differently in release build
How get item ID from ListFragment in android?
Receive bluetooth connection changes after reboot
Encrypting plain-text passwords and passing variables to xml for display in android
android html5 video fullscreenchange not called on entering fullscreen
Want to create API for my android application done using Intel XDK
Gps not getting location
Spannable Text is not working in Dialog Fragment
© Copyright 2017 Publishing Limited. All rights reserved.