Android App Development for Beginners - 19 video tutorials confusion!

0 Karan Narula · September 4, 2015
I am currently learning Android App development right after I finished the whole series of Java for Beginners and 25 videos of Intermediate Java from thenewboston. Since I started Android App development from newboston I first encountered (int) (aka casting) in one of the videos, and I had no clue what it does. Based on my research from the internet, it pretty much converts from one type of data to integer. I am now in the 19th tutorial of Android development and I got confused in this following code:

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button buckysButton=(Button)findViewById(R.id.buckysButton);

buckysButton.setOnClickListener( 

new Button.OnClickListener(){

public void onClick(View v){

TextView buckysText= (TextView) findViewById(R.id.buckysText);

buckysText.setText("Good Job Hoss!");

}

}
);

The two lines that confused me are "Button buckysButton=(Button)findViewById(R.id.buckysButton);" and "TextView buckysText= (TextView) findViewById(R.id.buckysText);". 

I am not sure what does (Button) and (Textview) actually do. Does it make the view type to "Button" or "Textview" ? Also I would like to ask if I am competent enough to learn Android app development based on the knowledge i had from from the Java tutorials offered from newboston, because I sometimes struggle during some of the Android tutorial videos. Thank you!

Post a Reply

Replies

Oldest  Newest  Rating
0 Karan Narula · September 6, 2015
Thank you! I understood now. :)
0 Dol Lod · September 5, 2015
The (Button) is doing a cast from a View into a button.All widgets are subclasses of View. 

The reason you are retrieving it is so you can control its properties. By using the ID, you are getting the specific element defined in the layout with that ID. Once you do that, you can invoke methods and properties of that element. Otherwise, you have only the GUI to manipulate the elements in your layout.
  • 1

Java / Android Development

107,076 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator