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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:30:30+00:00 2026-06-17T02:30:30+00:00

I have been trying to create to optimize my android code by creating an

  • 0

I have been trying to create to optimize my android code by creating an input validation method then calling it but it doesn’t work. I have tried debugging but nothing.
This is what i had the first time and it was working:

String s1 =startTime1.getText().toString();
if(TextUtils.isEmpty(startTime1.getText())){
    s1 = "00:00";
}
String e1 = endTime1.getText().toString();
if(TextUtils.isEmpty(endTime1.getText())){
    e1 = "00:00";
}

but after extracting the validation into this method and calling it each time the user enters input nothing seems to work.

public void emptyInputValidation(EditText time, String timeToString){
    if(TextUtils.isEmpty(time.getText())){
        timeToString = "00:00";
    }           
}


compute.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){

                try{
                    String s1 =startTime1.getText().toString();
                    emptyInputValidation(startTime1, s1);
                    String e1 = endTime1.getText().toString();
                    emptyInputValidation(endTime1, e1);
                    }
            catch (ParseException e){
                    e.printStackTrace();

                }     
}

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-17T02:30:31+00:00Added an answer on June 17, 2026 at 2:30 am

    In timeToString = "00:00"; of your function you are reassigning the parameter to "00:00", which is not reflected outside of the method. Here is the corrected code:

    public String emptyInputValidation(EditText time) {
        if(TextUtils.isEmpty(time.getText())){
            return "00:00";
        } else {
            return time.getText().toString();
        }           
    }
    

    Then simply call String s1 = emptyInputValidation(startTime1);

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

Sidebar

Related Questions

I have been trying to create a new google custom search engine, but when
I have been trying to create a directory in /sdcard programmatically, but it's not
I have been trying to create a deque in Java, but I get a
I have been trying to create a single codebase for both Iphone & Android
I have been trying to create a code like this: If you show 'us.gif'
I have been trying to optimize this code: def spectra(mE, a): pdf = lambda
I am developing in Android and have been trying to create an Async task
I have been trying to create a torrent site but I'm stuck with the
I have been trying to create a simple chunk of shell code that allows
I have been trying to create a notification window, but I'm struggling to figure

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.