Professional Documents
Culture Documents
Lab Record
Submitted
In partial fulfilment
For the award of the Degree of
Master of Computer Application
by
NAVIN SHARMA
Enrolment No.: CA14131711943
Activities in the system are managed as an activity stack. When a new activity
is started, it is placed on the top of the stack and becomes the running activity
-- the previous activity always remains below it in the stack, and will not come
to the foreground again until the new activity exits.
If an activity is in the foreground of the screen (at the top of the stack),
it is active or running.
If an activity has lost focus but is still visible (that is, a new non-full-
sized or transparent activity has focus on top of your activity), it
is paused. A paused activity is completely alive (it maintains all state
and member information and remains attached to the window
manager), but can be killed by the system in extreme low memory
situations.
If an activity is completely obscured by another activity, it is stopped. It
still retains all state and member information, however, it is no longer
visible to the user so its window is hidden and it will often be killed by
the system when memory is needed elsewhere.
If an activity is paused or stopped, the system can drop the activity
from memory by either asking it to finish, or simply killing its process.
When it is displayed again to the user, it must be completely restarted
and restored to its previous state.
onResume() called when activity will start interacting with the user.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.navin.rv.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
MainActivity.java
package com.navin.rv;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
public class MainActivity extends AppCompatActivity {
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
programmingList.setLayoutManager(new LinearLayoutManager(this));
programmingList.setAdapter(new programingAdapter(Languages));
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<ImageView
android:id="@+id/imgicon"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ln"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="24sp"
android:layout_gravity="center"
android:paddingLeft="16dp"
android:id="@+id/txtTitle"
/>
</LinearLayout>
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
this.data = data;
@Override
@Override
holder.txtTitle.setText(title);
}
@Override
return data.length;
ImageView imgicon;
TextView txtTitle;
super(itemView);
imgicon = itemView.findViewById(R.id.imgicon);
txtTitle = itemView.findViewById(R.id.txtTitle);
} }}
Q.3 Fragment
Ans .
Fragments
A Fragment represents a behavior or a portion of user interface in a FragmentActivity.
You can combine multiple fragments in a single activity to build a multi-pane UI and
reuse a fragment in multiple activities. You can think of a fragment as a modular
section of an activity, which has its own lifecycle, receives its own input events, and
which you can add or remove while the activity is running (sort of like a "sub activity"
that you can reuse in different activities).
Create activity_main.xml:-
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fragment1"
android:onClick="change"/>
<Button
android:id="@+id/button3"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_place"></FrameLayout>
</LinearLayout>
MainActivity:-
package com.navin.fragment2;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
if(view.getId()==R.id.button2) {
frag = new Fragment1();
getFragmentManager().beginTransaction().replace(R.id.fragment_place,frag).commit();
}
if(view.getId()==R.id.button3) {
frag = new Fragment2();
getFragmentManager().beginTransaction().replace(R.id.fragment_place,frag).commit();
}
}
}
MainActivity:-
package com.navin.fragment_demo;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml:-
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@drawable/image" />
<android.support.design.widget.TabLayout
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignBottom="@+id/image"
android:layout_alignParentStart="true"
app:tabGravity="fill"
app:tabIndicatorColor="#ffffff"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/white"></android.support.design.widget.TabLayout
>
<android.support.v4.view.ViewPager
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Create PageAdapter:-
package com.navin.fragment_demo;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
@Override
public int getCount() {
return pagecounnt;
}
public CharSequence getPageTitle(int position){
return tabtitle[position];
}
}
package com.navin.custom_navigationbar_with_actionbar;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawerLayout = findViewById(R.id.drawer);
navigationView = findViewById(R.id.nav_view);
}
}
activity_main.xml:-
<include layout="@layout/toolbar"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nagivation_header"
app:menu="@menu/mymenu"/>
</android.support.v4.widget.DrawerLayout>
Create toolbar.xml:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
Create navigation_header:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="160dp"
android:padding="16dp"
android:gravity="bottom"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:background="@color/colorAccent">
</LinearLayout>
Create menubar.xml:-
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:id="@+id/home" android:title="Home"></item>
<item android:id="@+id/setting" android:title="Setting"></item>
<item android:id="@+id/about" android:title="About"></item>
<item android:id="@+id/logout" android:title="Logout"></item>
</group>
<item android:title="Advance Option">
<menu>
<item android:title="Index"
android:id="@+id/index"></item>
<item android:id="@+id/email"
android:title="Email"></item>
</menu>
</item>
</menu>