Android: How to use a card view instead of a button









up vote
0
down vote

favorite












I have a dialog which currently opens on a button click and works fine but it means I have an ugly button that does not look good, I would prefer it to be opened from a CardView.



This is the card view:



CardView manager=findViewById(R.id.manager_card);
manager.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
);


And this is the dialog which currently opens from a button click:



Button btnLoginDialog;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);

// Init Widget Button and set click listener
btnLoginDialog = (Button) findViewById(R.id.btnLoginDialog);
btnLoginDialog.setOnClickListener(this);


@Override
public void onClick(View v)
if (v == btnLoginDialog)

// Create Object of Dialog class
final Dialog login = new Dialog(this);
// Set GUI of login screen
login.setContentView(R.layout.login_gui);
login.setTitle("Login to Pulse 7");

// Init button of login GUI
Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);

// Attached listener for login GUI button
btnLogin.setOnClickListener(new OnClickListener()
@Override
public void onClick(View v)
if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

// Validate Your login credential here than display message
Toast.makeText(SignInActivity.this,
"Login Sucessfull", Toast.LENGTH_LONG).show();

// Redirect to dashboard / home screen.
login.dismiss();
Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
startActivity(intent);

else

Toast.makeText(SignInActivity.this,
"Please enter valid Username and Password", Toast.LENGTH_LONG).show();



);
btnCancel.setOnClickListener(new OnClickListener()
@Override
public void onClick(View v)
login.dismiss();

);

// Make dialog box visible.
login.show();




I can't figure this out. I hope there is enough information there for someone to help me out.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I have a dialog which currently opens on a button click and works fine but it means I have an ugly button that does not look good, I would prefer it to be opened from a CardView.



    This is the card view:



    CardView manager=findViewById(R.id.manager_card);
    manager.setOnClickListener(new View.OnClickListener()
    @Override
    public void onClick(View view)
    );


    And this is the dialog which currently opens from a button click:



    Button btnLoginDialog;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_in);

    // Init Widget Button and set click listener
    btnLoginDialog = (Button) findViewById(R.id.btnLoginDialog);
    btnLoginDialog.setOnClickListener(this);


    @Override
    public void onClick(View v)
    if (v == btnLoginDialog)

    // Create Object of Dialog class
    final Dialog login = new Dialog(this);
    // Set GUI of login screen
    login.setContentView(R.layout.login_gui);
    login.setTitle("Login to Pulse 7");

    // Init button of login GUI
    Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
    Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
    final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
    final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);

    // Attached listener for login GUI button
    btnLogin.setOnClickListener(new OnClickListener()
    @Override
    public void onClick(View v)
    if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

    // Validate Your login credential here than display message
    Toast.makeText(SignInActivity.this,
    "Login Sucessfull", Toast.LENGTH_LONG).show();

    // Redirect to dashboard / home screen.
    login.dismiss();
    Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
    startActivity(intent);

    else

    Toast.makeText(SignInActivity.this,
    "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



    );
    btnCancel.setOnClickListener(new OnClickListener()
    @Override
    public void onClick(View v)
    login.dismiss();

    );

    // Make dialog box visible.
    login.show();




    I can't figure this out. I hope there is enough information there for someone to help me out.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a dialog which currently opens on a button click and works fine but it means I have an ugly button that does not look good, I would prefer it to be opened from a CardView.



      This is the card view:



      CardView manager=findViewById(R.id.manager_card);
      manager.setOnClickListener(new View.OnClickListener()
      @Override
      public void onClick(View view)
      );


      And this is the dialog which currently opens from a button click:



      Button btnLoginDialog;

      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_sign_in);

      // Init Widget Button and set click listener
      btnLoginDialog = (Button) findViewById(R.id.btnLoginDialog);
      btnLoginDialog.setOnClickListener(this);


      @Override
      public void onClick(View v)
      if (v == btnLoginDialog)

      // Create Object of Dialog class
      final Dialog login = new Dialog(this);
      // Set GUI of login screen
      login.setContentView(R.layout.login_gui);
      login.setTitle("Login to Pulse 7");

      // Init button of login GUI
      Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
      Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
      final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
      final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);

      // Attached listener for login GUI button
      btnLogin.setOnClickListener(new OnClickListener()
      @Override
      public void onClick(View v)
      if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

      // Validate Your login credential here than display message
      Toast.makeText(SignInActivity.this,
      "Login Sucessfull", Toast.LENGTH_LONG).show();

      // Redirect to dashboard / home screen.
      login.dismiss();
      Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
      startActivity(intent);

      else

      Toast.makeText(SignInActivity.this,
      "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



      );
      btnCancel.setOnClickListener(new OnClickListener()
      @Override
      public void onClick(View v)
      login.dismiss();

      );

      // Make dialog box visible.
      login.show();




      I can't figure this out. I hope there is enough information there for someone to help me out.










      share|improve this question















      I have a dialog which currently opens on a button click and works fine but it means I have an ugly button that does not look good, I would prefer it to be opened from a CardView.



      This is the card view:



      CardView manager=findViewById(R.id.manager_card);
      manager.setOnClickListener(new View.OnClickListener()
      @Override
      public void onClick(View view)
      );


      And this is the dialog which currently opens from a button click:



      Button btnLoginDialog;

      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_sign_in);

      // Init Widget Button and set click listener
      btnLoginDialog = (Button) findViewById(R.id.btnLoginDialog);
      btnLoginDialog.setOnClickListener(this);


      @Override
      public void onClick(View v)
      if (v == btnLoginDialog)

      // Create Object of Dialog class
      final Dialog login = new Dialog(this);
      // Set GUI of login screen
      login.setContentView(R.layout.login_gui);
      login.setTitle("Login to Pulse 7");

      // Init button of login GUI
      Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
      Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
      final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
      final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);

      // Attached listener for login GUI button
      btnLogin.setOnClickListener(new OnClickListener()
      @Override
      public void onClick(View v)
      if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

      // Validate Your login credential here than display message
      Toast.makeText(SignInActivity.this,
      "Login Sucessfull", Toast.LENGTH_LONG).show();

      // Redirect to dashboard / home screen.
      login.dismiss();
      Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
      startActivity(intent);

      else

      Toast.makeText(SignInActivity.this,
      "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



      );
      btnCancel.setOnClickListener(new OnClickListener()
      @Override
      public void onClick(View v)
      login.dismiss();

      );

      // Make dialog box visible.
      login.show();




      I can't figure this out. I hope there is enough information there for someone to help me out.







      java android






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 12:54









      DudeCoder

      1,234323




      1,234323










      asked Nov 11 at 11:27









      Haeata Mikaere

      82




      82






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Use this type,this will help you:-



          CardView manager=findViewById(R.id.manager_card);
          manager.setOnClickListener(new View.OnClickListener()
          @Override
          public void onClick(View view)


          final Dialog login = new Dialog(this);
          // Set GUI of login screen
          login.setContentView(R.layout.login_gui);
          login.setTitle("Login to Pulse 7");

          // Init button of login GUI
          Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
          Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
          final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
          final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);



          // Attached listener for login GUI button
          btnLogin.setOnClickListener(new OnClickListener()
          @Override
          public void onClick(View v)
          if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

          // Validate Your login credential here than display message
          Toast.makeText(SignInActivity.this,
          "Login Sucessfull", Toast.LENGTH_LONG).show();

          // Redirect to dashboard / home screen.
          login.dismiss();
          Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
          startActivity(intent);

          else

          Toast.makeText(SignInActivity.this,
          "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



          );
          btnCancel.setOnClickListener(new OnClickListener()
          @Override
          public void onClick(View v)
          login.dismiss();

          );

          // Make dialog box visible.
          login.show();



          );





          share|improve this answer




















          • Thanks that worked perfectly. I just could not figure it out.
            – Haeata Mikaere
            Nov 11 at 12:10

















          up vote
          0
          down vote













          Setting up OnClickListener on any Button and on any CardView is the exact same, in fact, setting OnClickListener on any class object which is a child class of View is exact same.



          That being said, just replace with OnClick code of Button with the OnClick code of CardView and that will work the same, like so:



          CardView manager=findViewById(R.id.manager_card);
          manager.setOnClickListener(new View.OnClickListener()
          @Override
          public void onClick(View view)
          // Create Object of Dialog class
          final Dialog login = new Dialog(this);
          // Set GUI of login screen
          login.setContentView(R.layout.login_gui);
          login.setTitle("Login to Pulse 7");

          // Init button of login GUI
          Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
          Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
          final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
          final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);

          // Attached listener for login GUI button
          btnLogin.setOnClickListener(new OnClickListener()
          @Override
          public void onClick(View v)
          if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

          // Validate Your login credential here than display message
          Toast.makeText(SignInActivity.this,
          "Login Sucessfull", Toast.LENGTH_LONG).show();

          // Redirect to dashboard / home screen.
          login.dismiss();
          Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
          startActivity(intent);

          else

          Toast.makeText(SignInActivity.this,
          "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



          );
          btnCancel.setOnClickListener(new OnClickListener()
          @Override
          public void onClick(View v)
          login.dismiss();

          );

          // Make dialog box visible.
          login.show();

          );





          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248259%2fandroid-how-to-use-a-card-view-instead-of-a-button%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            Use this type,this will help you:-



            CardView manager=findViewById(R.id.manager_card);
            manager.setOnClickListener(new View.OnClickListener()
            @Override
            public void onClick(View view)


            final Dialog login = new Dialog(this);
            // Set GUI of login screen
            login.setContentView(R.layout.login_gui);
            login.setTitle("Login to Pulse 7");

            // Init button of login GUI
            Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
            Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
            final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
            final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);



            // Attached listener for login GUI button
            btnLogin.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

            // Validate Your login credential here than display message
            Toast.makeText(SignInActivity.this,
            "Login Sucessfull", Toast.LENGTH_LONG).show();

            // Redirect to dashboard / home screen.
            login.dismiss();
            Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
            startActivity(intent);

            else

            Toast.makeText(SignInActivity.this,
            "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



            );
            btnCancel.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            login.dismiss();

            );

            // Make dialog box visible.
            login.show();



            );





            share|improve this answer




















            • Thanks that worked perfectly. I just could not figure it out.
              – Haeata Mikaere
              Nov 11 at 12:10














            up vote
            0
            down vote



            accepted










            Use this type,this will help you:-



            CardView manager=findViewById(R.id.manager_card);
            manager.setOnClickListener(new View.OnClickListener()
            @Override
            public void onClick(View view)


            final Dialog login = new Dialog(this);
            // Set GUI of login screen
            login.setContentView(R.layout.login_gui);
            login.setTitle("Login to Pulse 7");

            // Init button of login GUI
            Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
            Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
            final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
            final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);



            // Attached listener for login GUI button
            btnLogin.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

            // Validate Your login credential here than display message
            Toast.makeText(SignInActivity.this,
            "Login Sucessfull", Toast.LENGTH_LONG).show();

            // Redirect to dashboard / home screen.
            login.dismiss();
            Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
            startActivity(intent);

            else

            Toast.makeText(SignInActivity.this,
            "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



            );
            btnCancel.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            login.dismiss();

            );

            // Make dialog box visible.
            login.show();



            );





            share|improve this answer




















            • Thanks that worked perfectly. I just could not figure it out.
              – Haeata Mikaere
              Nov 11 at 12:10












            up vote
            0
            down vote



            accepted







            up vote
            0
            down vote



            accepted






            Use this type,this will help you:-



            CardView manager=findViewById(R.id.manager_card);
            manager.setOnClickListener(new View.OnClickListener()
            @Override
            public void onClick(View view)


            final Dialog login = new Dialog(this);
            // Set GUI of login screen
            login.setContentView(R.layout.login_gui);
            login.setTitle("Login to Pulse 7");

            // Init button of login GUI
            Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
            Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
            final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
            final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);



            // Attached listener for login GUI button
            btnLogin.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

            // Validate Your login credential here than display message
            Toast.makeText(SignInActivity.this,
            "Login Sucessfull", Toast.LENGTH_LONG).show();

            // Redirect to dashboard / home screen.
            login.dismiss();
            Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
            startActivity(intent);

            else

            Toast.makeText(SignInActivity.this,
            "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



            );
            btnCancel.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            login.dismiss();

            );

            // Make dialog box visible.
            login.show();



            );





            share|improve this answer












            Use this type,this will help you:-



            CardView manager=findViewById(R.id.manager_card);
            manager.setOnClickListener(new View.OnClickListener()
            @Override
            public void onClick(View view)


            final Dialog login = new Dialog(this);
            // Set GUI of login screen
            login.setContentView(R.layout.login_gui);
            login.setTitle("Login to Pulse 7");

            // Init button of login GUI
            Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
            Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
            final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
            final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);



            // Attached listener for login GUI button
            btnLogin.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

            // Validate Your login credential here than display message
            Toast.makeText(SignInActivity.this,
            "Login Sucessfull", Toast.LENGTH_LONG).show();

            // Redirect to dashboard / home screen.
            login.dismiss();
            Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
            startActivity(intent);

            else

            Toast.makeText(SignInActivity.this,
            "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



            );
            btnCancel.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            login.dismiss();

            );

            // Make dialog box visible.
            login.show();



            );






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 11 at 11:35









            Vishal Sharma

            7702212




            7702212











            • Thanks that worked perfectly. I just could not figure it out.
              – Haeata Mikaere
              Nov 11 at 12:10
















            • Thanks that worked perfectly. I just could not figure it out.
              – Haeata Mikaere
              Nov 11 at 12:10















            Thanks that worked perfectly. I just could not figure it out.
            – Haeata Mikaere
            Nov 11 at 12:10




            Thanks that worked perfectly. I just could not figure it out.
            – Haeata Mikaere
            Nov 11 at 12:10












            up vote
            0
            down vote













            Setting up OnClickListener on any Button and on any CardView is the exact same, in fact, setting OnClickListener on any class object which is a child class of View is exact same.



            That being said, just replace with OnClick code of Button with the OnClick code of CardView and that will work the same, like so:



            CardView manager=findViewById(R.id.manager_card);
            manager.setOnClickListener(new View.OnClickListener()
            @Override
            public void onClick(View view)
            // Create Object of Dialog class
            final Dialog login = new Dialog(this);
            // Set GUI of login screen
            login.setContentView(R.layout.login_gui);
            login.setTitle("Login to Pulse 7");

            // Init button of login GUI
            Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
            Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
            final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
            final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);

            // Attached listener for login GUI button
            btnLogin.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

            // Validate Your login credential here than display message
            Toast.makeText(SignInActivity.this,
            "Login Sucessfull", Toast.LENGTH_LONG).show();

            // Redirect to dashboard / home screen.
            login.dismiss();
            Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
            startActivity(intent);

            else

            Toast.makeText(SignInActivity.this,
            "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



            );
            btnCancel.setOnClickListener(new OnClickListener()
            @Override
            public void onClick(View v)
            login.dismiss();

            );

            // Make dialog box visible.
            login.show();

            );





            share|improve this answer
























              up vote
              0
              down vote













              Setting up OnClickListener on any Button and on any CardView is the exact same, in fact, setting OnClickListener on any class object which is a child class of View is exact same.



              That being said, just replace with OnClick code of Button with the OnClick code of CardView and that will work the same, like so:



              CardView manager=findViewById(R.id.manager_card);
              manager.setOnClickListener(new View.OnClickListener()
              @Override
              public void onClick(View view)
              // Create Object of Dialog class
              final Dialog login = new Dialog(this);
              // Set GUI of login screen
              login.setContentView(R.layout.login_gui);
              login.setTitle("Login to Pulse 7");

              // Init button of login GUI
              Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
              Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
              final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
              final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);

              // Attached listener for login GUI button
              btnLogin.setOnClickListener(new OnClickListener()
              @Override
              public void onClick(View v)
              if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

              // Validate Your login credential here than display message
              Toast.makeText(SignInActivity.this,
              "Login Sucessfull", Toast.LENGTH_LONG).show();

              // Redirect to dashboard / home screen.
              login.dismiss();
              Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
              startActivity(intent);

              else

              Toast.makeText(SignInActivity.this,
              "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



              );
              btnCancel.setOnClickListener(new OnClickListener()
              @Override
              public void onClick(View v)
              login.dismiss();

              );

              // Make dialog box visible.
              login.show();

              );





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                Setting up OnClickListener on any Button and on any CardView is the exact same, in fact, setting OnClickListener on any class object which is a child class of View is exact same.



                That being said, just replace with OnClick code of Button with the OnClick code of CardView and that will work the same, like so:



                CardView manager=findViewById(R.id.manager_card);
                manager.setOnClickListener(new View.OnClickListener()
                @Override
                public void onClick(View view)
                // Create Object of Dialog class
                final Dialog login = new Dialog(this);
                // Set GUI of login screen
                login.setContentView(R.layout.login_gui);
                login.setTitle("Login to Pulse 7");

                // Init button of login GUI
                Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
                Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
                final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
                final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);

                // Attached listener for login GUI button
                btnLogin.setOnClickListener(new OnClickListener()
                @Override
                public void onClick(View v)
                if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

                // Validate Your login credential here than display message
                Toast.makeText(SignInActivity.this,
                "Login Sucessfull", Toast.LENGTH_LONG).show();

                // Redirect to dashboard / home screen.
                login.dismiss();
                Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
                startActivity(intent);

                else

                Toast.makeText(SignInActivity.this,
                "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



                );
                btnCancel.setOnClickListener(new OnClickListener()
                @Override
                public void onClick(View v)
                login.dismiss();

                );

                // Make dialog box visible.
                login.show();

                );





                share|improve this answer












                Setting up OnClickListener on any Button and on any CardView is the exact same, in fact, setting OnClickListener on any class object which is a child class of View is exact same.



                That being said, just replace with OnClick code of Button with the OnClick code of CardView and that will work the same, like so:



                CardView manager=findViewById(R.id.manager_card);
                manager.setOnClickListener(new View.OnClickListener()
                @Override
                public void onClick(View view)
                // Create Object of Dialog class
                final Dialog login = new Dialog(this);
                // Set GUI of login screen
                login.setContentView(R.layout.login_gui);
                login.setTitle("Login to Pulse 7");

                // Init button of login GUI
                Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
                Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
                final EditText txtUsername = (EditText)login.findViewById(R.id.txtUsername);
                final EditText txtPassword = (EditText)login.findViewById(R.id.txtPassword);

                // Attached listener for login GUI button
                btnLogin.setOnClickListener(new OnClickListener()
                @Override
                public void onClick(View v)
                if(txtUsername.getText().toString().trim().equals("admin") && txtPassword.getText().toString().trim().equals("admin"))

                // Validate Your login credential here than display message
                Toast.makeText(SignInActivity.this,
                "Login Sucessfull", Toast.LENGTH_LONG).show();

                // Redirect to dashboard / home screen.
                login.dismiss();
                Intent intent = new Intent(getApplicationContext(), ManagerMenu.class);
                startActivity(intent);

                else

                Toast.makeText(SignInActivity.this,
                "Please enter valid Username and Password", Toast.LENGTH_LONG).show();



                );
                btnCancel.setOnClickListener(new OnClickListener()
                @Override
                public void onClick(View v)
                login.dismiss();

                );

                // Make dialog box visible.
                login.show();

                );






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 11:49









                DudeCoder

                1,234323




                1,234323



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248259%2fandroid-how-to-use-a-card-view-instead-of-a-button%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    政党

                    天津地下鉄3号線