Android Build an Interactive Story App User Input Finding Views by IDs

The ID for the button is button1. Don't forget to cast the generic View returned by the method!

The ID for the button is button1. Don't forget to cast the generic View returned by the method!

MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    protected Button exterminateButton;

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

        // Declare our view variables

    }

}

1 Answer

Yusuf Mohamed
Yusuf Mohamed
2,620 Points

This should do it.

exterminateButton = (Button) findViewById(R.id.button1);