Twitter Facebook Delicious Digg Stumbleupon Favorites More

Friday 28 July 2017

scroll view in android studio

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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.example.viraj.scrollview.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/><Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="HELLO VIRAJ"/><Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="HELLO VIRAJ"/><Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="HELLO VIRAJ"/><Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="HELLO VIRAJ"/><Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="HELLO VIRAJ"/><Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="HELLO VIRAJ"/>

  </LinearLayout>
</ScrollView>

Share:

Tuesday 25 July 2017

online registration and find in android database


1)main activity.java
package com.example.viraj.demodatabase;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void register(View view)
    {
        Intent intent=new Intent(MainActivity.this,Register.class);
        startActivity(intent);
    }
}
2)register.xmlpage
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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.example.viraj.demodatabase.Register">

    <EditText
        android:id="@+id/id_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="50dp"
        android:ems="10"
        android:hint="NAME"
        android:inputType="textPersonName"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <EditText
        android:id="@+id/id_password"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:hint="PASWORD"
        android:inputType="textPersonName"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_name"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <EditText
        android:id="@+id/id_contact"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="CONTACT"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_password"
        app:layout_constraintHorizontal_bias="0.0"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <EditText
        android:id="@+id/id_country"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="COUNTRY"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_contact"
        app:layout_constraintHorizontal_bias="0.0"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="32dp"
        android:onClick="reguser"
        android:text="Button"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_country"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <EditText
        android:id="@+id/id_find_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:hint="NAME"
        android:inputType="textPersonName"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_button" />

    <Button
        android:id="@+id/id_find_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp"
        android:layout_marginTop="24dp"
        android:onClick="finddata"
        android:text="Button"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_find_name"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintLeft_toRightOf="@+id/id_find_password"
        android:layout_marginLeft="8dp" />

    <EditText
        android:id="@+id/id_find_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="36dp"
        android:layout_marginTop="29dp"
        android:ems="10"
        android:hint="PASSWORD"
        android:inputType="textPersonName"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_find_name" />
</android.support.constraint.ConstraintLayout>


3)register .java page
package com.example.viraj.demodatabase;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Register extends AppCompatActivity {
    EditText e_name, e_password, e_contact, e_country, find_name,find_mobilenumber ;
    Button e_button,find_button;
    String name, password, country, contact,f_name,f_pass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        e_name = (EditText) findViewById(R.id.id_name);
        e_password = (EditText) findViewById(R.id.id_password);
        e_contact = (EditText) findViewById(R.id.id_contact);
        e_country = (EditText) findViewById(R.id.id_country);
       //-----------------------------------------------------
        find_name = (EditText) findViewById(R.id.id_find_name);
        find_mobilenumber=(EditText)findViewById(R.id.id_find_password);
        find_button=(Button)findViewById(R.id.id_button);



    }
//mainfeast me internet use ki permission bhi de
    public void reguser(View view) {
        name = e_name.getText().toString();
        password = e_password.getText().toString();
        contact = e_contact.getText().toString();
        country = e_country.getText().toString();
        //to cALL BACKGROUNDTASK FORM METHOD WE CREATE THIS 1)
       // Toast.makeText(getApplicationContext(),name,Toast.LENGTH_LONG).show();
        String method ="Register";
                //object of background task
        Backgroundtask backgroundtask=new Backgroundtask(this);
        backgroundtask.execute(method,name,password,contact,country);
        //finish();

    }

    public void finddata(View view) {
        f_name=find_name.getText().toString();
        f_pass=find_mobilenumber.getText().toString();
        String method ="find_transfer_code";
        //object of background task
        Backgroundtask backgroundtask=new Backgroundtask(this);
        backgroundtask.execute(method,f_name,f_pass);
    }
}

4)backgroundtask page java
package com.example.viraj.demodatabase;

import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

/**
 * Created by viraj on 26-Jun-17.
 */

public class Backgroundtask extends AsyncTask<String, Void, String> {
    //constructor created
    Context ctx;
    AlertDialog alertDialog;

    Backgroundtask(Context ctx) {
        this.ctx = ctx;
    }


    @Override
    protected void onPreExecute() {
        alertDialog = new AlertDialog.Builder(ctx).create();
        alertDialog.setTitle("CONTACT INFORMATION");

    }


    @Override
    //sab jagha string kara he void se change karke
    protected String doInBackground(String... params) {
//http://localhost/udemy/register.php http://10.0.2.2/udemy/register.php http://192.168.56.1/udemy/register.php  String reg_url = "https://applicatory-shadow.000webhostapp.com/register.php ";
        // String reg_url = "https://applicatory-shadow.000webhostapp.com/register.php ";
        //insert data ke liye php page
        String reg_url = "http://192.168.56.1/udemy/register.php";
        //find ke liye php page
        String find_url = "http://192.168.56.1/udemy/login.php";


        //EXTRACT KAR RAHE HE METHOD SE
        String method = params[0];//this param 0 is for method

        if (method.equals("Register")) {

            String name = params[1];
            String password = params[2];
            String contact = params[3];
            String country = params[4];

            try {
                //create object of url
                URL url = new URL(reg_url);
                //OBJECT OF HTTP URL CONN
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setDoOutput(true);
                OutputStream os = httpURLConnection.getOutputStream();
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
                String data = URLEncoder.encode("name", "UTF-8") + "=" + URLEncoder.encode(name, "UTF-8") + "&" +
                        URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8") + "&" +
                        URLEncoder.encode("contact", "UTF-8") + "=" + URLEncoder.encode(contact, "UTF-8") + "&" +
                        URLEncoder.encode("country", "UTF-8") + "=" + URLEncoder.encode(country, "UTF-8");
                bufferedWriter.write(data);
                bufferedWriter.flush();
                bufferedWriter.close();
                os.close();
                InputStream IS = httpURLConnection.getInputStream();
                IS.close();
                return "REGISTRATION SUCESS";
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
//niche code same he
        else if (method.equals("find_transfer_code")) {

            String find_name = params[1];
            String find_password = params[2];


            try {
                //create object of url find url
                URL url = new URL(find_url);
                //OBJECT OF HTTP URL CONN
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("POST");
                httpURLConnection.setDoOutput(true);
                OutputStream os = httpURLConnection.getOutputStream();
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
                String data = URLEncoder.encode("name", "UTF-8") + "=" + URLEncoder.encode(find_name, "UTF-8") + "&" +
                        URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(find_password, "UTF-8");
                bufferedWriter.write(data);
                bufferedWriter.flush();
                bufferedWriter.close();
                os.close();
                InputStream IS = httpURLConnection.getInputStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(IS, "iso-8859-1"));
                String response = "";
                String line = "";
                while ((line = bufferedReader.readLine()) != null) {
                    response += line;
                }
                bufferedReader.close();
                IS.close();
                httpURLConnection.disconnect();
                return response;


            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }


    @Override
    //sab jagha string kara he void se change karke
    protected void onPostExecute(String result1) {
        if (result1.equals("REGISTRATION SUCESS"))
        {
            Toast.makeText(ctx, result1, Toast.LENGTH_LONG).show();
        }
        else
            {
            alertDialog.setMessage(result1);
            alertDialog.show();
        }}


    @Override
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
    }}

Share:

localhost with android not working solution


  1. run you wamp server => click right mouse button => and click on "put online"
  2. then open your cmd as an administrateur , and pass in this commande word
  3. then lot of adresses show-up , then you have just to take the first one , it's look like this example: Adresse IPv4. . . . . . . . . . . . . .: 192.168.67.190 well done ! , that's the addresse, that you will use to connecte to your wampserver in local.
  4. open Control Panel >> System and Security >> Windows Firewall
  5. then go to control panel > system and security > windows firewall and turn windows firewall off
  6. now String reg_url = "http://192.168.00.0/udemy/register.php";

"""   past ur address  >>>>>>    192.168.00.0  """
Share:

Saturday 15 July 2017

Android sp and dp diffrence and its use

sp      ===   Scale-independent Pixels    =    sp for font-sizes

DP          ==== Density independence              =     FOR IMAGES 
Share:

Thursday 13 July 2017

student Management System android major minor project

main activity file  (https://www.codeproject.com/Articles/783073/A-Simple-Android-SQLite-Example)

package com.example.viraj.studentmanagementsystem;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabaseLockedException;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AlertDialog.Builder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    EditText ename, erollnumber, emarks;
    Button btnAdd, btnDelet, btnModify, btnView, btnViewall, btnShowinfo;
    SQLiteDatabase db;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Initializing controls
        ename = (EditText) findViewById(R.id.id_name);
        erollnumber = (EditText) findViewById(R.id.id_rollno);
        emarks = (EditText) findViewById(R.id.id_marks);

        btnAdd = (Button) findViewById(R.id.id_add_button);
        btnDelet = (Button) findViewById(R.id.id_delet_button);
        btnModify = (Button) findViewById(R.id.id_modifi_button);
        btnView = (Button) findViewById(R.id.id_view_button);
        btnViewall = (Button) findViewById(R.id.id_viewallbutton);
        btnShowinfo = (Button) findViewById(R.id.id_show_button);

// Registering event handlers
        btnAdd.setOnClickListener(this);
        btnModify.setOnClickListener(this);
        btnDelet.setOnClickListener(this);
        btnView.setOnClickListener(this);
        btnViewall.setOnClickListener(this);
        btnShowinfo.setOnClickListener(this);
        db = openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
        db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name VARCHAR,marks VARCHAR);");
    }

    @Override
    public void onClick(View v) {
        // Adding a record
        if (v == btnAdd) {// Checking empty fields
            if (ename.getText().toString().trim().length() == 0 ||
                    erollnumber.getText().toString().trim().length() == 0 ||
                    emarks.getText().toString().trim().length() == 0) {
                showMessage("ERROR", "PLZ PROVIDE ALL THE RECORD");
                return;
            }
            // Inserting record
            db.execSQL("INSERT INTO student VALUES('" + ename.getText() + "','" + erollnumber.getText() + "','" + emarks.getText() + "')");
            showMessage("SUCESSFULLY", "RECORD ADDED SUCESSFULLY");
            clearText();
        }
        if (v==btnDelet)
        {
            //check for emptu record
            if (erollnumber.getText().toString().trim().length()==0)
            {
                showMessage("ERROR","PLZ ENTER ROLL NO" );
                return;
            }
            // Searching roll number
            Cursor c=db.rawQuery("SELECT * FROM student WHERE rollno='"+erollnumber.getText()+"'", null);
            if(c.moveToFirst())
            {
                // Deleting record if found
                db.execSQL("DELETE FROM student WHERE rollno='"+erollnumber.getText()+"'");
                showMessage("Success", "Record Deleted");
            }
            else
            {
                showMessage("Error", "Invalid Rollno");
            }
            clearText();
        }
        // Modifying a record
        if(v==btnModify)
        {
            // Checking empty roll number
            if(erollnumber.getText().toString().trim().length()==0)
            {
                showMessage("Error", "Please enter Rollno");
                return;
            }
            // Searching roll number
            Cursor c=db.rawQuery("SELECT * FROM student WHERE rollno='"+erollnumber.getText()+"'", null);
            if(c.moveToFirst())
            {
                // Modifying record if found
                db.execSQL("UPDATE student SET name='"+ename.getText()+"',marks='"+erollnumber.getText()+
                        "' WHERE rollno='"+erollnumber.getText()+"'");
                showMessage("Success", "Record Modified");
            }
            else
            {
                showMessage("Error", "Invalid Rollno");
            }
            clearText();
        }
        // Viewing a record
        if(v==btnView)
        {
            // Checking empty roll number
            if(erollnumber.getText().toString().trim().length()==0)
            {
                showMessage("Error", "Please enter Rollno");
                return;
            }
            // Searching roll number
            Cursor c=db.rawQuery("SELECT * FROM student WHERE rollno='"+erollnumber.getText()+"'", null);
            if(c.moveToFirst())
            {
                // Displaying record if found
                ename.setText(c.getString(1));
                emarks.setText(c.getString(2));
            }
            else
            {
                showMessage("Error", "Invalid Rollno");
                clearText();
            }
        }
        // Viewing all records
        if(v==btnViewall)
        {
            // Retrieving all records
            Cursor c=db.rawQuery("SELECT * FROM student", null);
            // Checking if no records found
            if(c.getCount()==0)
            {
                showMessage("Error", "No records found");
                return;
            }
            // Appending records to a string buffer
            StringBuffer buffer=new StringBuffer();
            while(c.moveToNext())
            {
                buffer.append("Rollno: "+c.getString(0)+"\n");
                buffer.append("Name: "+c.getString(1)+"\n");
                buffer.append("Marks: "+c.getString(2)+"\n\n");
            }
            // Displaying all records
            showMessage("Student Details", buffer.toString());
        }
// Displaying info
        if(v==btnShowinfo)
        {
            showMessage("THIS LEARNING APP CREATED FOR LEARNING PURPOSE ONLY", "WRITTEN AGAIN FOR MY SELF HELP https://www.codeproject.com/Articles/783073/A-Simple-Android-SQLite-Example");
        }

    }


    private void showMessage(String title, String message) {
        Builder builder = new Builder(this);
        builder.setCancelable(true);
        builder.setTitle(title);
        builder.setMessage(message);
        builder.show();
    }

    public void clearText() {
        ename.setText("");
        erollnumber.setText("");
        emarks.setText("");
        erollnumber.requestFocus();
    }
}


xml file

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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.example.viraj.studentmanagementsystem.MainActivity"
    android:background="#2196F3"
    android:orientation="vertical"
    >

    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="495dp"
        android:orientation="vertical"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="8dp">


        <EditText
            android:id="@+id/id_rollno"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:ems="10"
            android:hint="ENTER ROLL NO"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/id_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:ems="10"
            android:hint="ENTER NAME" />

        <EditText
            android:id="@+id/id_marks"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:ems="10"
            android:hint="ENTER MARKS"
            android:inputType="textPersonName" />

        <Button
            android:id="@+id/id_add_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="#CDDC39"
            android:text="ADD" />

        <Button
            android:id="@+id/id_delet_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="#CDDC39"
            android:text="DELETE" />

        <Button
            android:id="@+id/id_modifi_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="#CDDC39"
            android:text="MODIFY" />

        <Button
            android:id="@+id/id_view_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="#CDDC39"
            android:text="VIEW" />

        <Button
            android:id="@+id/id_viewallbutton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="#CDDC39"
            android:text="VIEW ALL" />

        <Button
            android:id="@+id/id_show_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="#CDDC39"
            android:text="SHOW" />
    </LinearLayout>
</android.support.constraint.ConstraintLayout>

Share:

Wednesday 5 July 2017

BMI calculator pro version

BMI calculator pro version

MAIN ACTIVITY .JAVA FILE

package com.example.viraj.ttest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private EditText weight;
    private EditText height;
    private Button button;
    private TextView result_bmi;
    private TextView result_text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        weight = (EditText) findViewById(R.id.id_weight);
        height = (EditText) findViewById(R.id.id_height);
        result_bmi = (TextView) findViewById(R.id.id_bmiis);
        result_text = (TextView) findViewById(R.id.id_youare);

        button = (Button) findViewById(R.id.id_button);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                double weightget;
                double heightget;
                double bmi;
                String msg;
if (weight.getText().toString().equals("") && height.getText().toString().equals(""))
{
    Toast.makeText(getApplicationContext(),"NO VALID VALUES",Toast.LENGTH_LONG).show();
}
                weightget = Double.parseDouble(weight.getText().toString());
                heightget = Double.parseDouble(height.getText().toString());

                bmi = heightget * heightget;
                double bmi2= weightget / bmi;
result_bmi.setText(String.valueOf(bmi2));

                if (bmi2<18.5)
                {
result_text.setText("UNDER WEIGHT");
                }
                else if (bmi2 > 18.5 && bmi2 < 25)
                {
                    result_text.setText("NORMAL");
                }
                else if (bmi2 > 25 )
                {
                    result_text.setText("OVER WEIGHT");
                }
            }
        });
    }
}



ACTIVITY MAIN XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    android:background="#CDDC39"
    tools:context="com.example.viraj.ttest.MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="40dp"
        android:text="WEIGHT"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <EditText
        android:id="@+id/id_weight"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="40dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="40dp"
        android:text="HEIGHT"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_weight"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <EditText
        android:id="@+id/id_height"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="40dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView2"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="40dp"
        android:background="#212121"
        android:elevation="11dp"
        android:text="CALCULATE BMI"
        android:textAlignment="center"
        android:textColor="#CDDC39"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_height"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <TextView
        android:id="@+id/id_bmiis"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="21dp"
        android:text="YOUR B M I IS"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_button"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp" />

    <TextView
        android:id="@+id/id_youare"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="40dp"
        android:text="YOUR ARE"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_bmiis" />
</android.support.constraint.ConstraintLayout>

Share:

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab