Twitter Facebook Delicious Digg Stumbleupon Favorites More

Monday 26 June 2017

online registration with php android

1) main page xml code

<?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.MainActivity">

    <Button
        android:id="@+id/id_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="123dp"
        android:onClick="register"
        android:text="REGISTER"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/id_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="141dp"
        android:text="LOGIN"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_register" />
</android.support.constraint.ConstraintLayout>



main java page 

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);
    }
}

android mainfeast page

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.viraj.demodatabase">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".Register"></activity>
    </application>

</manifest>


second page 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.demodatabase.Register">

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

    <EditText
        android:id="@+id/id_password"
        android:layout_width="match_parent"
        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" />

    <EditText
        android:id="@+id/id_contact"
        android:layout_width="match_parent"
        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" />

    <EditText
        android:id="@+id/id_country"
        android:layout_width="match_parent"
        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" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="match_parent"
        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.support.constraint.ConstraintLayout>

second 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;
    Button e_button;
    String name, password, country, contact;

    @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);
       // e_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();

    }
}


third sirf java class banana he

package com.example.viraj.demodatabase;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
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;

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

    @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
        String reg_url = " http://192.168.12.3//udemy/register.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();
            }
        }
        return null;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    //sab jagha string kara he void se change karke
    protected void onPostExecute(String result1) {
        Toast.makeText(ctx, result1, Toast.LENGTH_LONG).show();
    }

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

Share:

Sunday 25 June 2017

database connection query part 1

<?php

$username="root";
$password="";
$host="localhost";
$database="project";
$conn=mysqli_connect($host,$username,$password,$database);
if(!$conn)
{
echo "CONNECTION FAIL";
}
else
{
echo "CONNECT SUCESSFULLY";
}

?>
Share:

Monday 19 June 2017

Intent Implicit and explicit

Intent can be bascially used to communicate between 2 activities inside the same app or to communicate between two activities in different app.

There are two types of intent 
1. Explicit Intent
2. Implicit Intent 

Implicit Intent - In implicit intent communication takes place between 2 activities of different application .

Implicit intent is basically used for starting services like
Like phonecall, sms, maps, etc 

Explicit Intent - In explicit Intent the communication takes place between 2 activities inside the same application .



implicit intant 

activity to website 

Explicit Intent

one activity to another activity of same app


IMPLICIT INTENT JAVA FILE

package com.example.viraj.blog_17_implicitintent;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button b=(Button)findViewById(R.id.id_button);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent=new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("http://android-tutorialss.blogspot.com/"));
                startActivity(intent);

            }
        });
    }
}


EXPLICIT INTENT

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

startActivity(intent);  

Share:

Activity lifecycle

JAVA  FILE

package com.example.viraj.blog_16_activitylifecycle;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    public MainActivity() {
    }

    @Override
    protected void onStart() {
        super.onStart();
        Toast.makeText(getApplicationContext(),"onStart",Toast.LENGTH_LONG).show();
    }

    @Override
    protected void onStop() {
        super.onStop();
        Toast.makeText(getApplicationContext(),"onStop",Toast.LENGTH_LONG).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Toast.makeText(getApplicationContext(),"onDestroy",Toast.LENGTH_LONG).show();
    }

 
    @Override
    protected void onPause() {
        super.onPause();
        Toast.makeText(getApplicationContext(),"onPause",Toast.LENGTH_LONG).show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        Toast.makeText(getApplicationContext(),"onResume",Toast.LENGTH_LONG).show();
    }

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


    }
}

Share:

Sunday 18 June 2017

RATING BAR ANDROID STUDIO

JAVA FILE
package com.example.viraj.blog_13_ratingbar;

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

public class MainActivity extends AppCompatActivity {
private RatingBar rb1;
    private Button b1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rb1=(RatingBar)findViewById(R.id.id_ratingBar);
        b1=(Button)findViewById(R.id.id_check);

        rb1.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                Toast.makeText(getApplicationContext(),"STAR IS : "+ rating,Toast.LENGTH_LONG).show();
            }
        });
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(),"STAR IS : "+ rb1.getRating(),Toast.LENGTH_LONG).show();
            }
        });

    }
}

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.blog_13_ratingbar.MainActivity">

    <RatingBar
        android:id="@+id/id_ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="64dp"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="8dp"
        app:layout_constraintVertical_bias="0.052"
        android:numStars="5"
        android:rating="2.0"
        android:stepSize="1"
        />

    <Button
        android:id="@+id/id_check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="144dp"
        android:text="CHECK"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ratingBar"
        app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>


Share:

Listview

JAVA FILE
package com.example.viraj.blog_12_listiew_javastringarraypage;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
ListView lv1;
    final String [] name_1=new String[]{
            "viraj","nilesh","abdesh","gaurov","rajpandey","sumit","nikhil","milind","dlgoyal"
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lv1=(ListView)findViewById(R.id.id_listview);
        ArrayAdapter <String> adapter_123=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android.R.id.text1,name_1);
    //assign the adapter to listview
        lv1.setAdapter(adapter_123);
lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        int int_12_position=position;
        String clickview_name=lv1.getItemAtPosition(int_12_position).toString();
        Toast.makeText(getApplicationContext(),clickview_name,Toast.LENGTH_LONG).show();
    }
});
    }
}

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.blog_12_listiew_javastringarraypage.MainActivity">

    <ListView
        android:id="@+id/id_listview"
        android:layout_width="368dp"
        android:layout_height="495dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp" />
</android.support.constraint.ConstraintLayout>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
nice explanation
WEBSITE https://androidexample.com/Create_A_Simple_Listview_-_Android_Example/index.php?view=article_discription&aid=65
In this android example creating a simple listview to display a array values.

activity_list_view_android_example.xml File

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
         <ListView
              android:id="@+id/list"
              android:layout_height="wrap_content"
              android:layout_width="match_parent">
         </ListView>
</LinearLayout>

Explanation :
Define ListView in xml file


   <ListView
        android:id="@+id/list"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
    </ListView>


=========================================================================================

ListViewAndroidExample.java File

    public class ListViewAndroidExample extends Activity {
        ListView listView ;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_list_view_android_example);
            
            // Get ListView object from xml
            listView = (ListView) findViewById(R.id.list);
            
            // Defined Array values to show in ListView
            String[] values = new String[] { "Android List View", 
                                             "Adapter implementation",
                                             "Simple List View In Android",
                                             "Create List View Android", 
                                             "Android Example", 
                                             "List View Source Code", 
                                             "List View Array Adapter", 
                                             "Android Example List View" 
                                            };
    
            // Define a new Adapter
            // First parameter - Context
            // Second parameter - Layout for the row
            // Third parameter - ID of the TextView to which the data is written
            // Forth - the Array of data
    
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
              android.R.layout.simple_list_item_1, android.R.id.text1, values);
    
    
            // Assign adapter to ListView
            listView.setAdapter(adapter); 
            
            // ListView Item Click Listener
            listView.setOnItemClickListener(new OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView<?> parent, View view,
                     int position, long id) {
                    
                   // ListView Clicked item index
                   int itemPosition     = position;
                   
                   // ListView Clicked item value
                   String  itemValue    = (String) listView.getItemAtPosition(position);
                      
                    // Show Alert 
                    Toast.makeText(getApplicationContext(),
                      "Position :"+itemPosition+"  ListItem : " +itemValue , Toast.LENGTH_LONG)
                      .show();
                 
                  }
    
             }); 
        }
    
    }
Explanation:
 Adapters are used to provide the data to the ListView
   Parameters:
       simple_list_item_1 :  Android internal layout view
       android.R.id.text1    :  In Android internal layout view already defined text fields to show data
        values                       :  User defined data array.
           ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
          android.R.layout.simple_list_item_1, android.R.id.text1, values);
           // Assign adapter to ListView
          listView.setAdapter(adapter); 
When Click on list item then onItemClick method in ListView Item Click Listener called

         listView.setOnItemClickListener(new OnItemClickListener() {
                      @Override
                      public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                        
                       // ListView Clicked item index
                       int itemPosition     = position;
                       
                       // ListView Clicked item value
                       String  itemValue    = (String) listView.getItemAtPosition(position);
                          
                        // Show Alert 
                        Toast.makeText(getApplicationContext(),
                          "Position :"+itemPosition+"  ListItem : " +itemValue , Toast.LENGTH_LONG)
                          .show();
                     
                      }
              });    


Share:

Search This Blog

Popular Posts

Pages

how to make crores from 1 lakh in stock markets in 1 year

how to make crores from 1 lakh in stock markets in 1 year

Blogger Tutorials

Blogger Templates

Sample Text

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