Friday, 24 July 2015

Lesson 5- Fragments

This took me a while to understand.

But here's the break down.

Before Honeycomb the usual navigation was from one activity to the next.

With fragments, it was possible for several user components to exist within a single activity.

Each fragment involves a single XML file with a java class.


Create an XML file with 2 relativelayout components.

Now create 2 XML files with a design/background of your choice and create 2 java class files coresponding to them.

public class Fragmentone extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View v=inflater.inflate(R.layout.fragmentonelayout,container,false);
    return v;
}
}

This is what your java class will look like.

You'll need onCreateView and you'll have to return the view with the inflated XML file.


Now in your main activity, you'll have to access the class.

FragmentManager fm=getFragmentManager();
                FragmentTransaction ft=fm.beginTransaction();
                Fragmentone f1=new Fragmentone();
                ft.add(R.id.fr1_id, f1);
                ft.commit();


Use a fragment manager, and assign it to a fragmenttransaction after using begintransaction()
Then create a object of your fragment class, to invoke the inflater.

Then add the realtivelayout id, with your class object.

Finally commit.

Tuesday, 21 July 2015

Lesson 4- Life Cycle

1) Intent filter is inside the initial activity you want to launch.
2)When you open the app it goes

onCreate
onStart
onResume

3)An activity is in pause as long as you can partially see it. Like Google Play's "Do you wish to install popup. The activity behind it, is currently in pause()

4)Once it is fully gone, it goes into onstop()

5) Why use onpause?

  • Stop animations or other ongoing actions that could consume CPU.
  • Commit unsaved changes, but only if users expect such changes to be permanently saved when they leave (such as a draft email).
  • Release system resources, such as broadcast receivers, handles to sensors (like GPS), or any resources that may affect battery life while your activity is paused and the user does not need them.
6)Call super class when using onPause()

Why?

The classes that make up the Android SDK can be incredibly complex. For instance, both activities and fragments must perform a number of operations in order to function properly (i.e. managing life cycle, optimizing memory usage, drawing the layout to the screen, etc.). Requiring the client to make a call to the base class (often at the beginning of the method) ensures that these operations are still performed, while still providing a reasonable level of abstraction for the developer.


7)Onpause is good when you're sure the users want options like autosave. Such as drafting an email. In that case, it'll be a temporary save and it'll be fast. But operations like writing to a database should be implemented on OnStop. Otherwise you'll see the activity lag.

8)Use onResume to initalize components that were paused in OnPause();

9)OnStop is called when your app isn't visible anymore.

Eg. Using the multitasking button to switch from one app to the next

Eg. Switching from one activity to the next . When you hit the back button, the original activity will go into onrestart()

10) Onrestart() jumps into onstart() so you can perform tasks that are essential when the app starts for the first time or starting again, like checking if your gps is enabled.

11)If you  rotate your screen, your current activity is killed and restarted from onCreate() (since it has to draw the layout all over again.)

In that case EditText text entered wouldn't be lost, but saved variable values may be lost.

So you can save variables before clearing the activity by using onsavedinstance() and accessing it with a bundle.

Add data to the bundle with .putint(String name,int value)

Call the superclass afterwards.

12)To access the saved data, use onrestorestate() after the super.onCreate(savedinstance), just be sure to check if the saved instance is null.

You can also implement it as a separate function just like onsavedinstance(), but in this case, it'll be called after the onStart() method and not right after onCreate() 

Saturday, 18 July 2015

Lesson 3- Other devices

1) A better reason why all your strings are stored in a resource called Strings.xml. It's easier to support multiple languages!

All you have to do is create a separate folder for the language you want to use, and define a strings.xml in it.

Eg. values-fr folder, would mean for France.

So inside it define your strings such as "hello world" as "Bonjour". Android willl automatically pick the right language depending on the language you use on your phone.

2)To create different layouts create different folders such as
layouts
layouts-land (For landscape)
layouts-large (For large devices)
layouts-large-land(For large devices and landscape)

3) For pixel densities you have xhdpi, hdpi,mdpi,ldpi

The ratio is
2.0
1.5
1.0
.75

So if you're creating an image for xhdpi as 200x200 pixels , you'll need to resize the image to 150x150 and place it in the hdpi drawable folder for phones of hdpi.

4) If you need to check the version of android you're running, and add features depending on that use

build.version.sdk_int > build.version_codes.(Your android version)

Eg. You can set action bars if the version.code is greater than honeycomb. Otherwise omit it.

Lesson 2- Action Bars

1) Action bars can be used for easy access of controls.
   (Though it does take up some screen space, I'm not sure how I feel about that. Maybe they could add a swipe feature to pull the action bar down)

2) It's only available from 3.0 or API 11. So update your min sdk to 11 if you want to use it. If you want to use sdk7, you'll have to use the support libraries and use a theme.AppCompat library.

3) You can add action buttons to the action bar by adding <item> to res/menu/main.xml

    ShowasAction is an attribute that determines whether to show the button or not.
   Eg. Ifroom means that, if there's room on the actionbar then display it.

4) You can add the items to the action bar in the onCreateOptionsMenu(Menu menu) method.

5) To specify the action,  use a switch case in onOptionsItemSelected(Menuitem item) to match the clicked buttons id with the ids present and implement a method once the case is found.

6) Instead of creating a button and intents to return back to the home screen, you can define the parent activity in you manifest file. Under your child activity, specify parentActivityName to your parent activity. Then to enable the up button, go to your child class java file and add getActionBar().setDisplayHomeAsUpEnable(true); This is a clean and easy way to return back to your parent activity.

7) You can use a theme by using application android:theme. You have a bunch of predefined themes.

Holo
Holo light etc

Use an appcompat theme if you're on sdk 7


8) To style the action bar, create an XML file, and give your style a name. Reference this name from the theme tag in your manifest file.

Set the parent to the theme you want your application to use. From there, you can specify item such as actionbarstyle and give it a name.

Define the name as a separate tag, giving it the name, parent theme, and item tags such as background.

9) If you want to overlay your action bar just set windowActionBarOverlay to true

 
 

Tuesday, 14 July 2015

Lesson 1

Notes:

1) ViewGroups are containers like relativelayout or linear layouts.
    Views are the widgets like buttons, edittext, etc.
    Viewgroups define how views are to be presented.

2) Use string resources rather than hardcoding strings. It'll make the updation of strings much more simpler if needed, as all the strings will be located in a single XML file.

3) layout_weight. It's an attribute for a widget in a XML file.

   It gives proportions.

  Like a recipe is 2 parts lemon and 1 part soda. If you give a weight to one widget a 1 and another as  2. 1+2=3. So your first widget will have 1/3 of the remaining free space and the other will have 2/3.
Remember to set width as 0dp to avoid confusion.

4) Intents are defined as
Intent intent=new Intent(this,theactivitytobeinvoked.class);
intent.putExtra(keyvalue,actual value);
//define the keyvalue as a constant string so it doesn't collide with other app interactions

5) Receiving it at the other end

Intent intent=getIntent();
String string=intent.getStringExtra(theoriginalactivity.keyname);


Tuesday, 26 May 2015

Ninjasmack source code

This is the source code for the game "Ninjasmack" that I made.

Check out the app here : https://play.google.com/store/apps/details?id=com.psiuol21.smashstack&hl=en

(This is only the java files)

First Acitivity.java

package com.example.smashstack;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import com.psiuol21.smashstack.R;

public class FirstAct extends ActionBarActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
   getActionBar().hide();
setContentView(R.layout.activity_first);
tv=(TextView)findViewById(R.id.textView1);
   Typeface mFont = Typeface.createFromAsset(getAssets(), "fonts/FONTX.TTF");
   tv.setTypeface(mFont);
   tv.setTextColor(Color.parseColor("#FFF000"));
   tv.setText("NINJASMACK");


}

public void enter(View v)
{
Intent intent=new Intent(FirstAct.this,MainActivity.class);
startActivity(intent);
finish();


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.first, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}



}






MainActivity.java


package com.example.smashstack;

import java.util.Random;
import java.util.concurrent.TimeUnit;

import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.psiuol21.smashstack.R;

public class MainActivity extends ActionBarActivity {

private float x1,x2,y1,y2;
RelativeLayout root;
int count=0;
int cuts[]=new int[] {0,0,0,0};
ImageView down,up,left,right;
MediaPlayer mediaPlayer;
final Handler handler= new Handler();
long starttime;
long remainingTime=12000;
Runnable runnable;
static final int MIN_DISTANCE = 150;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
   getActionBar().hide();
setContentView(R.layout.org);
mediaPlayer = MediaPlayer.create(this, R.raw.music);
mediaPlayer.start();
down=(ImageView)findViewById(R.id.down);
up=(ImageView)findViewById(R.id.up);
left=(ImageView)findViewById(R.id.left);
right=(ImageView)findViewById(R.id.right);
Thread thread = new Thread() {
   @Override
   public void run() {
       try {
       
           while(true) {
            Random rand = new Random();
            int randomNum = rand.nextInt((4-0));    
            while(cuts[0]==1 || cuts[1]==1 || cuts[2]==1 || cuts[3]==1);
          if(cuts[0]==0 && cuts[1]==0 && cuts[2]==0 && cuts[3]==0)
          {
          cuts[randomNum]=1;
         
          }
          runOnUiThread(new Runnable() {
    @Override
    public void run() {
     if(cuts[0]==1)
    right.setVisibility(View.VISIBLE);
     else if(cuts[1]==1)
     left.setVisibility(View.VISIBLE);
     else if(cuts[2]==1)
     down.setVisibility(View.VISIBLE);
     else if(cuts[3]==1)
     up.setVisibility(View.VISIBLE);

//stuff that updates ui

   }
});
           }
       } catch (Exception e) {
           e.printStackTrace();
       }
     
   }
};
thread.start();
 

runnable=new Runnable() {
    @Override
    public void run() {
   
   
     
        // Do something after 5s = 5000ms
    // mediaPlayer.release();
    // mediaPlayer=null;
    Intent intent=new Intent(MainActivity.this,LastActivity.class);
   
    intent.putExtra("score", count);
startActivity(intent);
finish();
   // Toast.makeText(getApplicationContext(), count+"", Toast.LENGTH_LONG).show();
    }
};
// handler.postDelayed(runnable, remainingTime);
 

}


 

@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

/**
* A placeholder fragment containing a simple view.
*/
public void onPause()
{
 super.onPause();
 
mediaPlayer.pause();
 
 handler.removeCallbacks(runnable);
 long elapsedTime = System.nanoTime();
//  elapsedTime=TimeUnit.SECONDS.convert(elapsedTime, TimeUnit.MILLISECONDS);
elapsedTime=(elapsedTime-starttime)/1000000;
   System.out.println(elapsedTime+"");
 remainingTime =  remainingTime- (elapsedTime);


}
@Override
public void onResume(){
   super.onResume();
   // put your code here...
   mediaPlayer.start();
   starttime = System.nanoTime();

   handler.postDelayed(runnable, remainingTime);
 

}

@Override
public boolean onTouchEvent(MotionEvent event)
{  
 
    switch(event.getAction())
    {
      case MotionEvent.ACTION_DOWN:
          x1 = event.getX();  
          y1 = event.getY();
      break;         
      case MotionEvent.ACTION_UP:
          x2 = event.getX();
          y2= event.getY();
          if(Math.abs(x2-x1)>Math.abs(y2-y1))
          {
          if(x2>x1)
          {
          float deltaX = x2 - x1;
          if(cuts[0]==1)
          {
         
          if (Math.abs(deltaX) > MIN_DISTANCE)
          {
        //   Toast.makeText(this, "left2right swipe", Toast.LENGTH_SHORT).show ();
          root=(RelativeLayout)findViewById(R.id.root);
        root.setBackgroundResource(R.drawable.hor);
        count++;
         
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                // Do something after 5s = 5000ms
                root.setBackgroundResource(R.drawable.org);
            }
        }, 200);
       
        right.setVisibility(View.INVISIBLE);
        cuts[0]=0;
          }
          else
          {
              // consider as something else - a screen tap for example
          }
          }
          }
          else
          {
          float deltaX = x2 - x1;
          if(cuts[1]==1)
          {
         
          if (Math.abs(deltaX) > MIN_DISTANCE)
          {
     //     Toast.makeText(this, "right2left swipe", Toast.LENGTH_SHORT).show ();
          root=(RelativeLayout)findViewById(R.id.root);
        root.setBackgroundResource(R.drawable.hor);
        count++;
        final Handler handler = new Handler();
         
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                // Do something after 5s = 5000ms
                root.setBackgroundResource(R.drawable.org);
            }
        }, 200);
       
       left.setVisibility(View.INVISIBLE);
       cuts[1]=0;
          }
          else
          {
              // consider as something else - a screen tap for example
          }
          } 
          }
          }
          else
          {
             if(y2>y1)
            {
             if(cuts[2]==1)
            {
            float deltaX = y2 - y1;
            if (Math.abs(deltaX) > MIN_DISTANCE)
            {
          //   Toast.makeText(this, "up2down swipe", Toast.LENGTH_SHORT).show ();
            root=(RelativeLayout)findViewById(R.id.root);
          root.setBackgroundResource(R.drawable.ver);
          count++;
          final Handler handler = new Handler();
          handler.postDelayed(new Runnable() {
              @Override
              public void run() {
                  // Do something after 5s = 5000ms
                  root.setBackgroundResource(R.drawable.org);
              }
          }, 200);
          down.setVisibility(View.INVISIBLE);
          cuts[2]=0;
            }
            else
            {
                // consider as something else - a screen tap for example
            }
            }
            }
            else
            {
            float deltaX = y2 - y1;
           if(cuts[3]==1)
            {
            if (Math.abs(deltaX) > MIN_DISTANCE)
            {
         //   Toast.makeText(this, "down2up swipe", Toast.LENGTH_SHORT).show ();
            root=(RelativeLayout)findViewById(R.id.root);
          root.setBackgroundResource(R.drawable.ver);
          count++;
          final Handler handler = new Handler();
          handler.postDelayed(new Runnable() {
              @Override
              public void run() {
                  // Do something after 5s = 5000ms
                  root.setBackgroundResource(R.drawable.org);
              }
          }, 200);
          up.setVisibility(View.INVISIBLE);
          cuts[3]=0;
         
            }
            else
            {
                // consider as something else - a screen tap for example
            }
            }
            
            }
          
          }
      break;   
    }           
    return super.onTouchEvent(event);       
}

}





LastActivity.java


package com.example.smashstack;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

import com.psiuol21.smashstack.R;

public class LastActivity extends ActionBarActivity {
TextView tv,tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
   getActionBar().hide();
setContentView(R.layout.activity_last);
   int score = getIntent().getIntExtra("score",0);
  // Toast.makeText(getApplicationContext(), score, Toast.LENGTH_SHORT).show();
   tv=(TextView)findViewById(R.id.textView1);
   tv2=(TextView)findViewById(R.id.textView2);
   Typeface mFont = Typeface.createFromAsset(getAssets(), "fonts/FONTX.TTF");
   tv.setTypeface(mFont);
   tv.setTextColor(Color.parseColor("#FFF000"));
   tv.setText(score+"");
   tv2.setTypeface(mFont);
   tv2.setTextColor(Color.parseColor("#FFF000"));
   if(score<5)
   tv2.setText("WHITE BELT");
   else if(score<10)
   tv2.setText("YELLOW BELT");
   else if(score<15)
   tv2.setText("GREEN BELT");
   else if(score<20)
   tv2.setText("BLUE BELT");
   else if(score<25)
   tv2.setText("RED BELT");
   else if(score<30)
   tv2.setText("BLACK BELT");
   
}
private boolean MyStartActivity(Intent aIntent) {
   try
   {
       startActivity(aIntent);
       return true;
   }
   catch (ActivityNotFoundException e)
   {
       return false;
   }
}

public void rateus(View v)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
    //Try Google play
    intent.setData(Uri.parse("market://details?id=com.psiuol21.smashstack"));
    if (!MyStartActivity(intent)) {
        //Market (Google play) app seems not installed, let's try to open a webbrowser
        intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.psiuol21.smashstack"));
        if (!MyStartActivity(intent)) {
            //Well if this also fails, we have run out of options, inform the user.
            Toast.makeText(this, "Could not open Android market, please install the market app.", Toast.LENGTH_SHORT).show();
        }
    }}
@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.last, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

/**
* A placeholder fragment containing a simple view.
* @return 
*/
public void goback(View v)
{
Intent intent=new Intent(LastActivity.this,MainActivity.class);
startActivity(intent);
finish();
}

}


Sunday, 8 February 2015

CGPA Calculator

I recently made a CGPA Calculator app in which each sem was separated as a different class.

I'll post the code for one class (Semester 3) and it's xml. Follow the same procedures for the rest.

Pick up the app here:https://play.google.com/store/apps/details?id=com.psiuol21.cgpa

Java Code

package com.example.cgpa;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.psiuol21.cgpa.R;

public class S3Activity extends ActionBarActivity {
EditText emII,ecskills,pscp,co,stld,edc,pgmlab,ldlab,sgpatext;
TextView emIIt,ecskillst,pscpt,cot,stldt,edct,pgmlabt,ldlabt;
float sgpa,temp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
   getActionBar().hide();
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/FARRAY.otf");
setContentView(R.layout.activity_s3);
emIIt = (TextView) findViewById(R.id.emII);
ecskillst= (TextView) findViewById(R.id.Economics);
pscpt= (TextView) findViewById(R.id.PSCP);
cot= (TextView) findViewById(R.id.CO);
stldt= (TextView) findViewById(R.id.STLD);
edct= (TextView) findViewById(R.id.EDC);
pgmlabt= (TextView) findViewById(R.id.Programminglab);
ldlabt= (TextView) findViewById(R.id.LogicDesignlab);

emIIt.setTypeface(tf);
ecskillst.setTypeface(tf);
pscpt.setTypeface(tf);
cot.setTypeface(tf);
stldt.setTypeface(tf);
edct.setTypeface(tf);
pgmlabt.setTypeface(tf);
ldlabt.setTypeface(tf);

emII=(EditText)findViewById(R.id.emIImarks);
ecskills=(EditText)findViewById(R.id.Economicsmarks);
pscp=(EditText)findViewById(R.id.PSCPmarks);
co=(EditText)findViewById(R.id.COmarks);
stld=(EditText)findViewById(R.id.STLDmarks);
edc=(EditText)findViewById(R.id.EDCmarks);
pgmlab=(EditText)findViewById(R.id.Programminglabmarks);
ldlab=(EditText)findViewById(R.id.LogicDesignlabmarks);


}

public float grade(EditText x)
{
int y=Integer.parseInt(x.getText().toString());
if(y>=136)
return 10;
else if(y>=121)
return 9;
else if(y>=106)
return 8;
else if(y>=91)
return 7;
else if(y>=83)
return 6;
else if(y>=75)
return (float) 5.5;
else
return 0;

}

public void calculate(View v)
{

if(emII.getText().toString().equals("") ||
 ecskills.getText().toString().equals("") ||
 pscp.getText().toString().equals("") ||
 co.getText().toString().equals("") ||
 stld.getText().toString().equals("") ||
 edc.getText().toString().equals("") ||
 pgmlab.getText().toString().equals("") ||
 ldlab.getText().toString().equals(""))
Toast.makeText(getApplicationContext(),"Please enter all the fields", Toast.LENGTH_LONG).show();
else
{
Toast.makeText(getApplicationContext(), "Calculating", Toast.LENGTH_SHORT).show();
//sgpatext=(EditText)findViewById(R.id.sgpa);

temp=(4*(grade(emII)+grade(ecskills)+grade(pscp)+grade(co)+grade(stld)+grade(edc)))+2*(grade(pgmlab)+grade(ldlab));
sgpa=temp/28;
//Toast.makeText(getApplicationContext(), sgpa+"", Toast.LENGTH_SHORT).show();
// sgpatext.setText(sgpa+"");
Intent myintent=new Intent(S3Activity.this, Sgpacalc.class).putExtra("S3marks", sgpa);
startActivity(myintent);
}

         //Log.d(TAG, "Sending data to status activity intent: " +data);
     


}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.s3, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

/**
* A placeholder fragment containing a simple view.
*/


}



XML Code

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    tools:context="com.example.cgpa.S3Activity"
    tools:ignore="MergeRootFrame"
     android:background="@drawable/androidback" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="664dp" >

    <TextView
        android:id="@+id/emII"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Engineering Maths II"
        android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="#FFFFFF" />

    <EditText
        android:id="@+id/emIImarks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/emII"
        android:ems="10"
        android:inputType="number"
         android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/Economics"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/emIImarks"
        android:text="Economics and Comm Skills"
        android:textAppearance="?android:attr/textAppearanceMedium" 
         android:textColor="#FFFFFF"/>

    <EditText
        android:id="@+id/Economicsmarks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/Economics"
        android:ems="10"
        android:inputType="number"
         android:textColor="#FFFFFF" >

       
    </EditText>

    <TextView
        android:id="@+id/PSCP"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/Economicsmarks"
        android:text="Computer Programming"
        android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="#FFFFFF" />

    <EditText
        android:id="@+id/PSCPmarks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/PSCP"
        android:ems="10"
        android:inputType="number" 
         android:textColor="#FFFFFF"/>

    <TextView
        android:id="@+id/CO"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/PSCPmarks"
        android:text="Computer Organization"
        android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="#FFFFFF" />

    <EditText
        android:id="@+id/COmarks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/CO"
        android:ems="10"
        android:inputType="number" 
         android:textColor="#FFFFFF"/>

    <TextView
        android:id="@+id/STLD"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/COmarks"
        android:text="Switching Theory"
        android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="#FFFFFF" />

    <EditText
        android:id="@+id/STLDmarks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/STLD"
        android:ems="10"
        android:inputType="number"
         android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/EDC"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/STLDmarks"
        android:text="Electronic Devices and Circuits"
        android:textAppearance="?android:attr/textAppearanceMedium"
         android:textColor="#FFFFFF" />

    <EditText
        android:id="@+id/EDCmarks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/EDC"
        android:ems="10"
        android:inputType="number"
         android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/Programminglab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/EDCmarks"
        android:text="Programming Lab"
        android:textAppearance="?android:attr/textAppearanceMedium" 
         android:textColor="#FFFFFF"/>

    <EditText
        android:id="@+id/Programminglabmarks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/Programminglab"
        android:ems="10"
        android:inputType="number"
         android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/LogicDesignlab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/Programminglabmarks"
        android:text="Logic Design Lab"
        android:textAppearance="?android:attr/textAppearanceMedium" 
         android:textColor="#FFFFFF"/>

    <EditText
        android:id="@+id/LogicDesignlabmarks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/LogicDesignlab"
        android:ems="10"
        android:inputType="number"
         android:textColor="#FFFFFF" />

    <ImageButton
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/LogicDesignlabmarks"
        android:layout_centerHorizontal="true"
        android:background="@null"
        android:onClick="calculate"
        android:src="@drawable/calc" />

</RelativeLayout>
</ScrollView>