Opening an activity with a button

1

I'm having a problem opening my activity in various forums and have not found the answer. I have the activity "TelaDeLogin" and the activity "Feed", and already tried to open in several ways, here is the button xml code:

<Button
        android:id="@+id/BtnEntrar"
        style="@style/BotaoComFundo"
        android:layout_marginTop="@dimen/espacamento_Pequeno"
        android:text="@string/entrar"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/editTextSenha"
        app:layout_constraintVertical_bias="0.0"
        android:onClick="logar"/>

Here are the ways I tried to program the button through the java code:

import android.app.Fragment;
import android.content.Intent;
import android.support.design.widget.NavigationView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class TelaDeLogin extends AppCompatActivity {
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tela_de_login);

        button = (Button) findViewById(R.id.BtnEntrar);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                logar(v);
            }
        });
    }
    public void logar(View v) {
        Intent intent = new Intent(TelaDeLogin.this, Feed.class);
        startActivity(intent);
    }
}

It used to be this way:

import android.app.Fragment;
import android.content.Intent;
import android.support.design.widget.NavigationView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class TelaDeLogin extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tela_de_login);

         public void logar(View view){
        Intent i = new Intent(TelaDeLogin.this, Feed.class);
        startActivity(i);
    }

}

Considering the codes, public class of my feed is declared as follows:

public class Feed extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

And I noticed that all the screens that have the Navigation View to Toolbar and FeedDrawer I can not open through a button, so how do I get the Feed through of the button, because whenever I click on the button of an error, however in the profile screen that did not have the "implement" of NavigationView open, and put the "implement" Navigation View of error and closes the app too. >

PS: the Feed page normally opens to open it first, I just can not access it through the

    
asked by anonymous 10.07.2018 / 17:54

1 answer

1

It has no secret, you can do within% direct%.

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), Feed.class);
            startActivity(intent);
        }
    });
    
10.07.2018 / 19:30