Android Widgets 1 7 August 2018

Slides:



Advertisements
Similar presentations
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Advertisements

Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Getting Started with Android APIs Ivan Wong. Motivation - “Datasheet” - Recently exposed to what’s available in Android - So let’s see what API’s are.
Package org.androidtown.database.query; import android.app.Activity; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase;
Social Media Apps Programming Min-Yuh Day, Ph.D. Assistant Professor Department of Information Management Tamkang University
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Android Dialog Boxes AlertDialog - Toast
Android - Broadcast Receivers
Programming with Android: Layouts, Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Presented By: Muhammad Tariq Software Engineer Android Training course.
로봇 모니터링 1/2 UNIT 20 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Message Queue Handler 2.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
Android ImageView and Splash Screen 1. After copying an image file (Ctrl-c or right click copy), right click and paste it into one of the res/drawable.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
User Interface Layout Interaction. EventsEvent Handlers/Listeners Interacting with a user.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Lab7 – Appendix.
Introduction to android
Lab7 – Advanced.
Android Programming - Features
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
several communicating screens
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Android -By Yogita Nirmal.
Android – Event Handling
Android – Read/Write to External Storage
Android Dialog Boxes AlertDialog - Toast
Picasso Revisted.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Software Engineering for Internet Applications
Android Programming Lecture 4
CS323 Android Model-View-Controller Architecture
Android Programming Lecture 6
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Sensor Programming
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 493/EEC 492 Android Sensor Programming
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
Android Project Structure, App Resources and Event Handling
Adding Components to Activity
CMPE419 Mobile Application Development
BLP 4216 MOBİL UYGULAMA GELİŞTİRME-2
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
CIS 470 Mobile App Development
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Android Widgets 1 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 1

Android Widget There are given a lot of android widgets with simplified examples such as Button, EditText, AutoCompleteTextView, ToggleButton, DatePicker, TimePicker, ProgressBar etc. 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID 2

Android Button Example Android Button represents a push-button. The android.widget.Button is subclass of TextView class and CompoundButton is the subclass of Button class. There are different types of buttons in android such as RadioButton, ToggleButton, CompoundButton etc. Here, we are going to create two textfields and one button for sum of two numbers. If user clicks button, sum of two input values is displayed on the Toast. Drag the component or write the code for UI in activity_main.xml 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

The generated code for the ui components will be like this: 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

Activity class package com.example.sumof2numbers; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { private EditText edittext1,edittext2; private Button buttonSum; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); addListenerOnButton(); } public void addListenerOnButton(){ edittext1=(EditText)findViewById(R.id.editText1); edittext2=(EditText)findViewById(R.id.editText2); buttonSum=(Button)findViewById(R.id.button1); buttonSum.setOnClickListener(new OnClickListener(){ @Override public void onClick(View view) { String value1=edittext1.getText().toString(); String value2=edittext2.getText().toString(); int a=Integer.parseInt(value1); int b=Integer.parseInt(value2); int sum=a+b; Toast.makeText(getApplicationContext(),String.valueOf(sum),Toast.LENGTH_LONG).show(); }); public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

OUTPUT 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

Android Toast Example Andorid Toast can be used to display information for the short period of time. A toast contains message to be displayed quickly and disappears after sometime. Toast class Toast class is used to show notification for a particular interval of time. After sometime it disappears. It doesn't block the user interaction. Constants of Toast class There are only 2 constants of Toast class which are given below. Methods of Toast class 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

Android Toast Example Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT).show();   Another code: Toast toast=Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT);   toast.setMargin(50,50);   toast.show();   Here, getApplicationContext() method returns the instance of Context. 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

Android Toast Example – Java Coding 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

Android Custom Toast Example activity_main.xml customtoast.xml File: activity_main.xml <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"       xmlns:tools="http://schemas.android.com/tools"       android:layout_width="match_parent"       android:layout_height="match_parent"       tools:context=".MainActivity" >          <TextView           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:layout_centerHorizontal="true"           android:layout_centerVertical="true"           android:text="@string/hello_world" />   </RelativeLayout>   <?xml version="1.0" encoding="utf-8"?>   <LinearLayout xmlns:androclass="http://schemas.android.com/apk/res/android"         android:id="@+id/custom_toast_layout"       android:layout_width="match_parent"       android:layout_height="match_parent"       android:orientation="vertical"       android:background="#F14E23"        >               <ImageView           android:id="@+id/custom_toast_image"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:contentDescription="@string/hello_world"           android:src="@drawable/ic_launcher"/>          <TextView           android:id="@+id/custom_toast_message"           android:contentDescription="@string/Toast"           android:text="@string/Toast" />   </LinearLayout>   7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

Activity class public class MainActivity extends Activity { @Override         public void onCreate(Bundle savedInstanceState) {               super.onCreate(savedInstanceState);               setContentView(R.layout.activity_main);                          //Creating the LayoutInflater instance               LayoutInflater li = getLayoutInflater();           //Getting the View object as defined in the customtoast.xml file               View layout = li.inflate(R.layout.customtoast,                 (ViewGroup) findViewById(R.id.custom_toast_layout));                       //Creating the Toast object                Toast toast = new Toast(getApplicationContext());               toast.setDuration(Toast.LENGTH_SHORT);               toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);               toast.setView(layout);//setting the view of custom toast layout               toast.show();           }           @Override           public boolean onCreateOptionsMenu(Menu menu) {               getMenuInflater().inflate(R.menu.activity_main, menu);               return true;      }   7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

Android ToggleButton Example Android Toggle Button can be used to display checked/unchecked (On/Off) state on the button. XML Attributes of ToggleButton class Methods of ToggleButton class 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

activity_main.xml 7 August 2018 <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"       xmlns:tools="http://schemas.android.com/tools"       android:layout_width="match_parent"       android:layout_height="match_parent"       tools:context=".MainActivity" >          <ToggleButton           android:id="@+id/toggleButton1"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:layout_alignParentLeft="true"           android:layout_alignParentTop="true"           android:layout_marginLeft="60dp"           android:layout_marginTop="18dp"           android:text="ToggleButton1"           android:textOff="Off"           android:textOn="On" />           android:id="@+id/toggleButton2"           android:layout_alignBaseline="@+id/toggleButton1"           android:layout_alignBottom="@+id/toggleButton1"           android:layout_marginLeft="44dp"           android:layout_toRightOf="@+id/toggleButton1"           android:text="ToggleButton2"       <Button           android:id="@+id/button1"           android:layout_below="@+id/toggleButton2"           android:layout_marginTop="82dp"           android:text="submit" />   </RelativeLayout>   7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

public class MainActivity extends Activity {       private ToggleButton toggleButton1, toggleButton2;       private Button buttonSubmit;       @Override       protected void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.activity_main);                      addListenerOnButtonClick();       }       public void addListenerOnButtonClick(){           //Getting the ToggleButton and Button instance from the layout xml file           toggleButton1=(ToggleButton)findViewById(R.id.toggleButton1);           toggleButton2=(ToggleButton)findViewById(R.id.toggleButton2);           buttonSubmit=(Button)findViewById(R.id.button1);              //Performing action on button click           buttonSubmit.setOnClickListener(new OnClickListener(){               @Override               public void onClick(View view) {                   StringBuilder result = new StringBuilder();                      result.append("ToggleButton1 : ").append(toggleButton1.getText());                      result.append("\nToggleButton2 : ").append(toggleButton2.getText());                   //Displaying the message in toast                   Toast.makeText(getApplicationContext(), result.toString(),Toast.LENGTH_LONG).show();               }                          });       public boolean onCreateOptionsMenu(Menu menu) {           // Inflate the menu; this adds items to the action bar if it is present.           getMenuInflater().inflate(R.menu.activity_main, menu);           return true;   }   Activity class 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID

Thank You 7 August 2018 S.RENUKADEVI/AP/SCD/INTRODUCTION TO ANDROID