CMPE419 Mobile Application Development

Slides:



Advertisements
Similar presentations
Client / Server Programming in Android Eclipse IDE Android Development Tools (ADT) Android SDK
Advertisements

Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
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 - Broadcast Receivers
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
Google map v2.
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
Mobile Software Development for Android - I397
Lab7 – Appendix.
Lab7 – Advanced.
Android Programming - Features
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Android N Amanquah.
several communicating screens
Adapting to Display Orientation
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Android Introduction Hello World.
Android Dr. Vaishali D. Khairnar IT Department
Android Notifications
Android Widgets 1 7 August 2018
Android – Read/Write to External Storage
Broadcast Receivers A Android Component where you can register for system or application events, receive and react to broadcast intent. Each broadcast.
Android Introduction Camera.
Mobile Device Development
Picasso Revisted.
CIS 470 Mobile App Development
CS323 Android Model-View-Controller Architecture
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
Many thanks to Jun Bum Lim for his help with this tutorial.
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,
HNDIT2417 Mobile Application 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
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
CMPE419 Mobile Application Development
BLP 4216 MOBİL UYGULAMA GELİŞTİRME-2
CMPE419 Mobile Application Development
Chapter 5 Your Second Activity.
Activities, Fragments, and Intents
Mobile Programming Broadcast Receivers.
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren 2018-2019 SPRING Computer Engineering Department CMPE419 AU

Adding New Page and Button, EditText, TextView

How to add a new page to the existing project? package com.example.buttonw; import android.app.Activity; import android.os.Bundle; public class ButtonMainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_button_main); } ButtonMainActivity.java

<RelativeLayout xmlns:android="http://schemas. android <RelativeLayout xmlns:android="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="${relativePackage}.${activityClass}" > </RelativeLayout> Activity_button_main.xml

For creating a new page : right click to layout directory and select from New-Activity Empty Activity

AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.buttonw" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".ButtonMainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

For the new activity we have to add the following code to the AndroidManifest.xml file: android:name=".NewActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.NEW" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>

Button, EditView and TextView TextView  is a label for displaying text EditView  is a textbox for entering a text Lets add a Button, an EditView and a TextView to the main activity.

Now lets enter a text and display it after pressing a button. For this we have to use Java code and create appropreate objects.

<RelativeLayout xmlns:android="http://schemas. android xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${relativePackage}.${activityClass}" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button1" android:layout_centerHorizontal="true" android:layout_marginTop="62dp" android:text="TextView" /> <EditText android:id="@+id/editText1" android:layout_alignParentTop="true" android:layout_marginTop="78dp" android:ems="10" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_below="@+id/editText1" android:layout_marginTop="60dp" android:text="Button" /> </RelativeLayout>

package com.example.buttonw; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class ButtonMainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_button_main); final TextView show=(TextView)findViewById(R.id.textView1); show.setText(""); final EditText all=(EditText)findViewById(R.id.editText1); Button b=(Button)findViewById(R.id.button1); b.setText("Display"); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub show.setText(all.getText()); } });

How to jump new activity? Create a New Button Use this button to jump to new acctivity. Button bb=(Button)findViewById(R.id.button2); bb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub startActivity(new Intent("android.intent.action.NEW")); } });

Example protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); show=(TextView) findViewById(R.id.TextView1); Inputtext=(EditText) findViewById(R.id.editText1); Display=(Button) findViewById(R.id.button1); View.OnClickListener eventh=new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub a=a+1; show.setText(Inputtext.getText()+"Button Pressed"+a); } }; Display.setOnClickListener(eventh);

Example Button a,c; TextView b; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b = (TextView) findViewById(R.id.textView1); a = (Button) findViewById(R.id.button1); c= (Button) findViewById(R.id.button2); // create click listener OnClickListener oclBtnOk = new OnClickListener() { public void onClick(View v) { // change text of the TextView switch (v.getId()){ case R.id.button1: b.setText("Button 1 clicked"); break; case R.id.button2: //b.setText("Button 2 clicked"); startActivity(new Intent("android.intent.action.NEW")); break;} } }; // assign click listener to the OK button (btnOK) a.setOnClickListener(oclBtnOk); c.setOnClickListener(oclBtnOk);