Saturday, January 26, 2013

Making Simple Mark Sheet in Android

1. Make an xml file for your application marksheet.xml

<?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="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Mark Sheet"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/edit_total"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number"
         android:hint="TOTAL Marks" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/edit_java"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number"
         android:hint="JAVA Marks" />

    <EditText
        android:id="@+id/edit_php"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number"
         android:hint="PHP Marks" />

    <EditText
        android:id="@+id/edit_html"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number"
        android:hint="HTML Marks" />

    <Button
        android:id="@+id/marks"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Marksheet" />

    <TextView
        android:id="@+id/tvresult"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.53"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>


2. Make a java class MarkShee.java

package com.example.login;
   
 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 MarkSheet extends Activity {

        Button mSheet;
        TextView result;
        EditText edit_total, edit_java, edit_php, edit_html;
        int total_no = 0, obtained_no = 0 , percent = 0, java_no, php_no, html_no;
       
       
        /** Called when the activity is first created. */

        @Override

        public void onCreate(Bundle savedInstanceState)
        {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.marksheet);
           
            edit_total = (EditText)findViewById(R.id.edit_total);
            edit_java = (EditText)findViewById(R.id.edit_java);
            edit_php = (EditText)findViewById(R.id.edit_php);
            edit_html = (EditText)findViewById(R.id.edit_html);
            mSheet = (Button)findViewById(R.id.marks);
            result = (TextView)findViewById(R.id.tvresult);
           
            mSheet.setOnClickListener(new View.OnClickListener(){



                public void onClick(View v) {

                    // TODO Auto-generated method stub
                    total_no = Integer.parseInt(edit_total.getText().toString());
                    java_no = Integer.parseInt(edit_java.getText().toString());
                    php_no = Integer.parseInt(edit_php.getText().toString());
                    html_no = Integer.parseInt(edit_html.getText().toString());
                    obtained_no = java_no + php_no + html_no;
                    percent = (obtained_no *100)/ total_no;

                    if(percent >= 33 )

                    {

                        result.setText("Total Marks are: "+ total_no + "\nObtained Marks are: "+obtained_no+"\nPercentage: "+ percent +"\nResult: Pass");

                    }

                    else

                    {

                        result.setText("Total Marks are: "+ total_no + "\nObtained Marks are: "+obtained_no+"\nResult: Fail");

                    }   
                }
            });
        }
    }


3. copy and past following code in AndroidMenifest.xml file

** Make sure that in android:name="com.example.login.MarkSheet" the last name should be your class name (as "MarkSheet" in this case)

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.login"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.login.MarkSheet"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize|stateVisible" >
          
            <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
    </application>

</manifest>


Now run your Project and Test your Application.

 

No comments:

Post a Comment