android app

9
INTRODUCING ANDROID APP Simple ToDo Develope r Mohd Ikram Kartikeya Verma PPT Design

Upload: kartikeya-verma

Post on 07-Aug-2015

22 views

Category:

Business


2 download

TRANSCRIPT

Page 1: Android app

INTRODUCING ANDROID APPSimple ToDo

Developer Mohd Ikram

Kartikeya VermaPPT Design

Page 2: Android app

ANDROID APPLICATION

Simple ToDo

MainActivity SecondActivity

Page 3: Android app

activity_main.xml

<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" android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"android:id="@+id/SimpleToDo">

<ListViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/listView"android:layout_alignParentTop="true"android:layout_alignParentStart="true"android:layout_above="@+id/btnAdd"android:textFilterEnabled="false"android:visibility="visible" />

<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Add"android:id="@+id/btnAdd"android:layout_alignParentBottom="true"android:layout_alignParentEnd="true" />

<EditTextandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/btnText"android:hint="Enter new Item"android:layout_alignParentBottom="true"android:layout_alignParentStart="true"android:layout_toStartOf="@+id/btnAdd"/>

</RelativeLazyout>

Page 4: Android app

activity_second.xml

<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" android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin"tools:context="com.interviewassignment.ikram.simpletodo.SecondActivity">

<EditTextandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/btnSecondText"android:layout_marginTop="91dp"android:layout_alignParentTop="true"android:layout_alignParentStart="true"android:layout_alignParentEnd="true" />

<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Save"android:layout_below="@+id/btnSecondText"android:id="@+id/btnsave"android:layout_marginStart="70dp"android:layout_alignTop="@+id/btndelete"android:layout_alignParentStart="true" />

<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Delete"android:layout_below="@+id/btnSecondText"android:id="@+id/btndelete"android:layout_centerVertical="true"android:layout_toEndOf="@+id/btnsave"android:layout_marginStart="50dp" /></RelativeLayout>

Page 5: Android app

Main activity

btnClick.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

/*getting the data from edit text and converting to String.*/

String textToDisplay = textInput.getText().toString();

/*leading and trailing whitespace omitted.*/

textToDisplay = textToDisplay.trim();

/*if text in edit text is not empty then it will add text dynamically to

listview otherwise it's won't add.*/

if (!textToDisplay.isEmpty()) {

arrayList.add(textToDisplay); //dynamically add String to arrayList

Toast.makeText(getApplicationContext(), "Item Saved",

Toast.LENGTH_LONG).show();

} else {

Toast.makeText(getApplicationContext(), "Please Insert Text",

Toast.LENGTH_LONG).show();

}

/*reset the edit text to empty string*/

textInput.setText("");

}

});

• Enter text here

• Tap on “ADD” button

• Text added to list

Following action will take place after clicking ADD button in main activity

Page 6: Android app

Main activity

list.setOnItemClickListener(new AdapterView.OnItemClickListener(){

@Override

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

/*A toast provides simple feedback about which item is clicked and it's position in a

small popup*/

Toast.makeText(getApplicationContext(), "" + (position+1) +") " +

arrayList.get(position) , Toast.LENGTH_SHORT).show();

/* getting text of item on which we clicked on ListView on screen */

String copyData = arrayList.get(position);

/* creating an intent to launch a new activity */

Intent intent = new Intent(getApplicationContext(),SecondActivity.class);

/* putting the data in the intent to send */

intent.putExtra("myOriginalKey",copyData);

intent.putExtra("myKeyPosition",position);

/* start the activity */

startActivityForResult(intent, Edit_Mode );

}

});

Tap on a particular item to edit/delete in another activity

Following action will take place after Tapping on any the item from list

Page 7: Android app

Second activity

btnSave.setOnClickListener(new View.OnClickListener(){

@Override

public void onClick(View v) {

/* getting the data from edit text and convert it to String. */

String editedText = textcopy.getText().toString();

Toast.makeText(getApplicationContext(), "New Text Saved" ,

Toast.LENGTH_SHORT).show();

/* After getting the data from edit text and reset it to empty

String. */

textcopy.setText("");

Intent intent = new Intent();

/* putting the data in the intent to send */

intent.putExtra("myEditedKey",editedText);

intent.putExtra("myEditedKeyPosition",position);

setResult( RESULT_EDIT , intent);

SecondActivity.this.finish();

}

});

• Tap item to edit • Then edit• Tap on “SAVE” button

• Auto return to list

Following action will take place after clicking SAVE button in Second activity

Page 8: Android app

btnDelete.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(), "Text Deleted",

Toast.LENGTH_LONG).show();

/* Reset edit text box to empty string */

textcopy.setText("");

Intent intent = new Intent();

/* putting the data in the intent to send */

intent.putExtra("myEditedKeyPosition",position);

setResult(RESULT_DELETE, intent);

SecondActivity.this.finish();

}

}); • Tap item to edit • Tap on “DELETE” button • Auto return to list

Second activityFollowing action will take place after clicking DELETE button in Second activity

Page 9: Android app

Thank you