Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren 2015-2016 SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren 2015-2016.

Similar presentations


Presentation on theme: "CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren 2015-2016 SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren 2015-2016."— Presentation transcript:

1 CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren 2015-2016 SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren 2015-2016 SPRING Computer Engineering Department CMPE419 AU

2 Adding New Page and Button, EditText, TextView

3 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

4 <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}" > Activity_button_main.xml

5 For creating a new page : right click to layout directory and select from New-Other-Android- Android XML File

6

7 Now we have to create Java Controller file for newpage.xml For this create a class under scr directory.

8

9 package com.example.buttonw; public class NewActivity { } Modify this class as an activity class: package com.example.buttonw; import android.app.Activity; public class NewActivity extends Activity{ }

10 We have to add onCreate() and setContentView to the NewActivity.java file.

11 package com.example.buttonw; import android.app.Activity; import android.os.Bundle; public class NewActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); } Now we have to connect our Java class to xml file by using setContentView setContentView(R.layout.newpage);

12 package com.example.buttonw; import android.app.Activity; import android.os.Bundle; public class NewActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.newpage); } Now we have to modify Manifest file.

13 AndroidManifest.xml <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" >

14 For the new activity we have to add the following code to the AndroidManifest.xml file: <activity android:name=".NewActivity" android:label="@string/app_name" >

15 <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" > <activity android:name=".NewActivity" android:label="@string/app_name" > DEFAULT for all other activities

16 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.

17

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

19

20

21

22 <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}" > <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_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="78dp" android:ems="10" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_marginTop="60dp" android:text="Button" />

23 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() { @Override public void onClick(View v) { // TODO Auto-generated method stub show.setText(all.getText()); } }); }

24 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")); } }); }


Download ppt "CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren 2015-2016 SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren 2015-2016."

Similar presentations


Ads by Google