public class FindBeerActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_beer);
}
Spinner color = (Spinner) findViewById(R.id.color);
TextView brands = (TextView) findViewById(R.id.brands);
public void onClickFindBeer(View view) {
//Get the selected item in the spinner
String beerType = String.valueOf(color.getSelectedItem());
//Display the selected item
brands.setText(beerType);
}
}
I know if I move the findviewbyid
's into the onclick
method, the code will run fine but i would like to understand why it wont work this way even though the setContentView has already been called.