University LECTURE 8 Connecting Real Device with Android Studio • On an Android based mobile phone, go to: ● Settings -> About Phone ● and tap “Build Number” 6 or 7 times. It will enable Developer Options in the settings. ● Now turn ON this Developer Options and USB Debugging inside this menu as well. ● Your device will now be listed in Available Devices drop down in the Android Studio. Let’s add some Action! • Click event on a Button: <Button android:layout_width="0dp" android:layout_height="wrap_content" android:onClick="sumCalc" android:layout_weight="1" android:text="Sum" /> • SumCalc is a function defined in your MainActivity.java Responding to Click Events • The Activity hosting the layout must then implement the corresponding method. • The method you declare in the android:onClick attribute must have a signture exactly as follows: ● Be public ● Return void ● Define a view as its only parameter (this will be the View that was clicked) Responding to Click Events public void sumCalc(View view) { // responding click event } Responding to Click Events • Using OnClickListener: Button button = (Button) findViewById(R.id.button_send); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Do something in response to button click } }); Android Studio Practical • Let’s create a simple app which adds two numbers (from EditText fields) and display their sum in a TextView. • Time to start recall concepts of Java. References • Book: – Chapter • https://developer.android.com/guide/topics/ui/controls/button#java