How to open a new screen through a Button ? (The Button is inside a Popup)

Asked

Viewed 70 times

-1

package com.example.ConsultoriaRuiz;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Browser;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AlertDialogLayout;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.example.ConsultoriaRuiz.ui.home.HomeFragment;
import com.getbase.floatingactionbutton.FloatingActionsMenu;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationView;

import java.net.URI;

public class Sobre extends AppCompatActivity {
    private AppBarConfiguration mAppBarConfiguration;
    private Button btnreceita, btndespesa;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sobre);
        Button btnreceita = (Button) findViewById(R.id.btnreceita);
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        NavigationView navigationView = findViewById(R.id.nav_view);

        btndespesa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), Sobre.class);
                startActivity(intent);
                // NÃO DÁ ERRO ALGUM, MAS O BUTTON NÃO CHAMA A PRÓXIMA TELA
                // O BUTTON ESTÁ DENTRO DE UM POPUP
            }
        });

        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.

    }
}
  • In your shared code the btndespesa nor receives a value. You shared the incomplete code or simply forgot to use findViewById to the btndespesa?

  • It has value, not shared, friend...

  • None of the buttons perform the given function, is there any difference ? By being inside Popup

  • I don’t know what you mean by Popup, but the findViewById of Sobre will only find elements that are in R.layout.activity_sobre. If your buttons are in this layout, they will be found, otherwise they will not be.

  • All buttons are in Layout and instantiated, Popup is basically a dialog

  • It does not give any error, runs and opens the APP normally, just does not perform the action of Buttons.

Show 1 more comment

2 answers

0

The right thing would be:

Intent intent = new Intent(getApplicationContext(), Sobre.class);
startActivity(intent);

Where you would pass within the relatives the context of the application, in case getApplicationContext() and the destination, as: destination.class;

You have put the same Activity that is the button as destination, so it will not work even.

0

Hello, I don’t understand why you are calling your own Activity being the one already active. The Intent function serves to open a new activity, example:

Intent Intent = new Intent(Mainactivity.this, Main2activity.class); startActivity(i);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.