Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPE419 Mobile Application Development

Similar presentations


Presentation on theme: "CMPE419 Mobile Application Development"— Presentation transcript:

1 CMPE419 Mobile Application Development
Asst.Prof.Dr.Ahmet Ünveren 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 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_button_main); } ButtonMainActivity.java

4 <RelativeLayout xmlns:android="http://schemas. android
<RelativeLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${relativePackage}.${activityClass}" > </RelativeLayout> Activity_button_main.xml

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

6

7

8 AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=" package="com.example.buttonw" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" > <activity android:name=".ButtonMainActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

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

10

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

12

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

14

15

16

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

18 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()); } });

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

20 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);

21 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);

22

23


Download ppt "CMPE419 Mobile Application Development"

Similar presentations


Ads by Google