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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:48:06+00:00 2026-05-20T03:48:06+00:00

My code: package com.example.linkingpage; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent;

  • 0

My code:

package com.example.linkingpage;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LinkingPage extends Activity {

     String tv,tv1;
    EditText name,pass;
     TextView x,y;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         Button button = (Button) findViewById(R.id.widget44);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                Intent obj = new Intent(LinkingPage.this,LinkingPage.class);
                startActivity(obj);

            }
        });

        x = (TextView) findViewById(R.id.widget46);
        y = (TextView) findViewById(R.id.widget47);
         name = (EditText)findViewById(R.id.widget41);
         pass = (EditText)findViewById(R.id.widget43);
        Button button1 = (Button) findViewById(R.id.widget45);
        button1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                 x.setText(tv);
                 y.setText(tv1);

                 tv = name.getText().toString();

                 if(tv.trim().equals("")) {
                     // text is empty
                     showDialog(EMPTY_TEXT_ALERT);
                 }


                 tv1 = pass.getText().toString();

                 if (tv1.trim().equals(""))
                 {
                   showDialog(EMPTY_TEXT_ALERT);

                 }

                  else
                  {Intent obj = new Intent(LinkingPage.this,ResourcePage.class);
                  obj.putExtra("name", name.getText().toString());                                          
                  obj.putExtra("pass", pass.getText().toString());
                      startActivity(obj);
                  }
           }
        });


    }
    private final static int EMPTY_TEXT_ALERT = 0;
    @Override
    public Dialog onCreateDialog(int id) {
        switch(id) {
            case EMPTY_TEXT_ALERT: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("Message:Field Empty!!!")
                       .setPositiveButton("OK", new DialogInterface.OnClickListener() {

                           @Override
                           public void onClick(DialogInterface dialog, int which) {
                               dialog.cancel();
                           }
                 });

                 return builder.create();
            }
        }

        return null;
    }

}

When both fields are kept empty, and button is clicked alert is generated. Same happens when only name field is filled. But when name field is kept empty and passwor is filled , then though an alert is generated but link to other page is also generated showing my password.How can i prevent this??

  • 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-05-20T03:48:07+00:00Added an answer on May 20, 2026 at 3:48 am

    Its because your your else that starts your next activity is only applying to your second if statement(the one for the password)

    this:

    if(tv.trim().equals("")) {
        // text is empty
        showDialog(EMPTY_TEXT_ALERT);
    }
    

    is completely separate from this:

    if (tv1.trim().equals(""))
    {
        showDialog(EMPTY_TEXT_ALERT);
    
    }else
    {
        Intent obj = new Intent(LinkingPage.this,ResourcePage.class);
        obj.putExtra("name",name.getText().toString());                                          
        obj.putExtra("pass", pass.getText().toString());
        startActivity(obj);
    }
    

    In order to make it check both of them you should do something like this:

    if(tv.trim().equals("") || tv1.trim().equals(""))
    {
        showDialog(EMPTY_TEXT_ALERT)
    }else{
        Intent obj = new Intent(LinkingPage.this,ResourcePage.class);
        obj.putExtra("name",name.getText().toString());                                          
        obj.putExtra("pass", pass.getText().toString());
        startActivity(obj);
    }
    

    And again I really cannot stress enough how much easier your could would be to understand if you used descriptive names for your variables instead of things like tv,tv1,button,button1,widget38 etc…

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

Sidebar

Related Questions

To be specific, I was trying this code: package hello; public class Hello {
I'm trying to determine how to modify SAP R/3 package code of an installed
I'm trying to use the Optiflag package in my Ruby code and whenever I
I'm using LaTeX 's listings package to format source code. Unfortunately I get curly
I am looking for a LaTeX package that does syntax highlighting on code. For
I am newbie in android application development. I am using the Form Stuff example
What libraries and/or packages have you used to create blog posts with code blocks?
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();
Code I have: cell_val = CStr(Nz(fld.value, )) Dim iter As Long For iter =

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.