DroidDraw Tutorial
Step ZeroThis tutorial will give you a brief introduction to developing a GUI application on Android using the DroidDraw user interface designer. This tutorial assumes that you have downloaded and installed the Android SDK. This tutorial also assumes that you are reasonably familiar with concepts in GUI programming and the Java programming language.Step OneGo to the DroidDraw UI Designer.Step TwoSet the root layout to RelativeLayoutStep ThreeSelect the "Layouts" tab.Step FourDrag and drop a LinearLayout object from the Layouts panel into the top-center of the screenStep FiveSelect the LinearLayout object and click on the properties tab to begin editing the layout properties. Change the width to "200px" and the height to "130px"Press "Apply" to apply your changes. |
Step SixGo to the "Widgets" tab.Step SevenDrag and drop two TextView objects and two EditText objects into the LinearLayout so that they alternate.Step EightDrag and drop a RadioGroup object into the LinearLayout. Drag and drop two RadioButton objects into the RadioGroup.Step NineDrag and drop a Button object into the root RelativeLayout below the LinearLayout object. It should align with the right edge of the LinearLayout.Step TenEdit the properties of each TextView object. Make text for the upper one read "Dollars" and make its style "bold". Make the lower one read: "Euros" and make its style bold also.Step ElevenEdit the properties of the upper EditText as follows:
Step Eleven and a halfRepeat step eleven with the second EditText under the "Euros" TextView, but make the id be "@+id/euros" |
Step TwelveEdit the first RadioButton so that its text reads: "Dollars to Euros" and its id is "@+id/dtoe".Edit the second RadioButton so that its text reads: "Euros to Dollars" and its id is "@+id/etod". Important Note: Step ThirteenEdit the Button so that its text reads: "Convert" and its id is "@+id/convert".The final GUI should look like: Step FourteenPress the "Generate" button to generate the layout XML. It will look something like thisStep FifteenIn Eclipse create a new android project. Cut and paste the XML from DroidDraw to replace the contents ofres/layout/main.xml .
At this point you should be able to run your GUI in Android. It should look something like this: Step SixteenThe last step is to actually code the currency conversion. There's not much to it, you can look up your GUI elements with:this.findViewById(R.id.<id>) .
Here is the complete code for the CurrencyConverter activity: Step SeventeenWell, that's it. I hope you enjoyed the tutorial. Comments and Questions to brendan.d.burns on gmail!import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.RadioButton; import android.widget.TextView; public class CurrencyConverter extends Activity implements OnClickListener { TextView dollars; TextView euros; RadioButton dtoe; RadioButton etod; Button convert; /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); dollars = (TextView)this.findViewById(R.id.dollars); euros = (TextView)this.findViewById(R.id.euros); dtoe = (RadioButton)this.findViewById(R.id.dtoe); dtoe.setChecked(true); etod = (RadioButton)this.findViewById(R.id.etod); convert = (Button)this.findViewById(R.id.convert); convert.setOnClickListener(this); } public void onClick(View v) { if (dtoe.isChecked()) { convertDollarsToEuros(); } if (etod.isChecked()) { convertEurosToDollars(); } } protected void convertDollarsToEuros() { double val = Double.parseDouble(dollars.getText().toString()); // in a real app, we'd get this off the 'net euros.setText(Double.toString(val*0.67)); } protected void convertEurosToDollars() { double val = Double.parseDouble(euros.getText().toString()); // in a real app, we'd get this off the 'net dollars.setText(Double.toString(val/0.67)); } } |