dimanche 30 septembre 2018

if statement not working in Android Studio

I am new to Android Studio. In my project, I am trying to use IF statement in a very simple setting (to activate a change) but it doesn't work. Your help will be greatly appreciated. Below is my code:

public class MainActivity extends AppCompatActivity {


private Button mBtLaunchActivity;
private Button Home;
int a = 0;


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

    Home = (Button) findViewById(R.id.home_button);

    mBtLaunchActivity = (Button) findViewById(R.id.map_button);

    mBtLaunchActivity.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            launchActivity();
            a = 1;

        }

    });

}

private void launchActivity() {

    if (a == 1){
        Home.setVisibility(View.INVISBLE);
    }

    Intent intent = new Intent(this, Activity3.class);
    startActivity(intent);

}

Aucun commentaire:

Enregistrer un commentaire