Helium3 Helium3 - 1 month ago 8x
Android Question

Android equivalent of IBActions and IBOutlets

I am thinking of starting with android development.

What are the equivalents of IBActions and IBOutlets in android?

Is it as easy as Interface Builder to setup connections to code?

Is it quick to learn the basics of android development if one knows java?


To your last question, I'd answer "yes".

You still wire up the interface to your code but currently you do this programmatically and on the fly: After giving a view an id by <Button android:id="@+id/myButton" /> or some such in your XML layout file you then call, in your code and after the layout has been created, View myButton = findViewById(R.layout.myButton). The latter is the equivalent of an IBOutlet and wiring it in IB except the connection is made when you need it. (You could also do this programmatically for the iPhone if you wanted.)

The equivalent of an IBAction is to use onClickListener, declaring myButton.setOnClickListener(this); and that this implements View.OnClickListener. You then override public void onClick(View v) and use a switch on v.id.

In practice this is all not as bad as I've made it sound. The major pain with developing for Android that I encounter is scaling the views for different devices.

If you grasp this and intents, the rest is pretty much plain ol' Java.