Showing posts with label androidbeginer. Show all posts
Showing posts with label androidbeginer. Show all posts

Thursday, 8 March 2018

Spinners in android using data adapter java and string use

Spinners in android using data adapter java  and  string use

button event toast make,

for the create a spinner have two method 

1)data adapter using java 
2)string file add spinner 

create single new  activity 


for both of spinner activity we are use 
1)activity_addspinarr .xml
2)addspinarr .java
3)strings.xml (  path > app>res>values> string.xml )


1)activity_addspinarr .xml


preview of activity_addspinarr .xml



code of activity_addspinarr .xml



<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.store.n01.addspinarr">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/spinner"
        android:layout_alignLeft="@+id/spinner"
        android:layout_alignStart="@+id/spinner"
        android:layout_marginBottom="57dp"
        android:layout_marginLeft="18dp"
        android:layout_marginStart="18dp"
        android:text="spinner"
        android:textSize="35dp" />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="12dp"
        android:layout_marginStart="12dp"
        android:layout_marginTop="111dp"
        android:entries="@array/gender_array"
        android:prompt="@string/gender_prompt" />

    <Spinner
        android:id="@+id/spinner2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/spinner1"
        android:layout_alignStart="@+id/spinner1"
        android:layout_below="@+id/spinner1"
        android:entries="@array/education_array"
        android:layout_marginTop="32dp" />

    <Spinner
        android:id="@+id/spinner3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_alignStart="@+id/textView2"
        android:layout_below="@+id/spinner2"
        android:layout_marginTop="67dp"
        android:entries="@array/education_array"
        android:prompt="@string/education_prompt" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="84dp"
        android:background="@drawable/btn_all"
        android:text="submit"
        android:textSize="35dp" />

</android.widget.RelativeLayout>


2)addspinarr .java

data adapter for spinner 3

package com.example.store.n01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class addspinarr extends AppCompatActivity {
    private Spinner spinner1 ,spinner2;
    private Button button4;
    private AdapterView.OnItemSelectedListener addListenerOnSpinnerItemSelection;

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

        addItemsOnSpinner2();
        addListenerOnButton();
        addListenerOnSpinnerItemSelection();

    }
public void addItemsOnSpinner2(){
        spinner2 = (Spinner)findViewById(R.id.spinner2);

        List<String> list = new ArrayList<String>();
        list.add ("jan");
        list.add("feb");
        list.add("march");
        list.add("april");
        list.add("may");
        list.add("june");
        list.add("dec");

    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner2.setAdapter(dataAdapter);

}
    public void addListenerOnSpinnerItemSelection(){
        spinner1 =(Spinner)findViewById(R.id.spinner1);
        spinner1.setOnItemSelectedListener(addListenerOnSpinnerItemSelection);

    }

//getselected item on click on submiit btn

    public void addListenerOnButton(){

    spinner1=(Spinner) findViewById(R.id.spinner1);
    spinner2=(Spinner)findViewById(R.id.spinner2);
    button4=(Button)findViewById(R.id.button4);


    button4.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {

            Toast.makeText(addspinarr.this,
                    "OnClickListener : "+
                            "\nSpinner 1 : "+ String.valueOf(spinner1.getSelectedItem())+
                            "\nSpinner 2 : "+ String.valueOf(spinner2.getSelectedItem()),
                    Toast.LENGTH_SHORT).show();
        }

    });
    }
}


3)strings.xml

add this code to xml file in given path
fore spinner1 and spinner2

<string name="gender_prompt">choose a gender</string>
    <string-array name="gender_array">
        <item>choose a gender</item>
        <item> male </item>
        <item> female </item>
    </string-array>
<string name="education_prompt">choose education</string>
    <string-array name="education_array">
        <item>choose education </item>
        <item>10th or below</item>
        <item>10+2 or below</item>
        <item>graduate</item>
        <item>post graduate</item>
    </string-array>



when button click make toast which has selected in 
spinner 1 ,2 & 3




Wednesday, 28 February 2018

submit a sign up button alldata pass to next text view activity

submit a sign up button
all typed data pass to next 
text view activity ,
data pass through last activity   


sign_up  activity preview :-




make new activity pass following step -  

right clik on app bar in project structure .> new>activity>empty activity> name file text_view  



now we have

1) activity_sign_up.xml
2)sign_up.java
3)activity_text_view.xml
4)text_view.java




code :-

1) activity_sign_up.xml
 
     in that activity we are use  
   </LinearLayout>
    </ScrollView>
as shown preview on top


activity_sign_up.xml

<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.store.n01.Sign_up">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:scrollbars="vertical">

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


            <EditText
                android:id="@+id/edit_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:ems="10"
                android:inputType="textPersonName"
                android:hint="Name" />

            <EditText
                android:id="@+id/edt_mobileno"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignEnd="@+id/edit_name"
                android:layout_alignRight="@+id/edit_name"
                android:layout_below="@+id/editText4"
                android:ems="10"
                android:inputType="textPersonName"
                android:hint="@string/mobile_no" />

            <EditText
                android:id="@+id/edt_passwardsu"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignEnd="@+id/editText5"
                android:layout_alignRight="@+id/editText5"
                android:layout_below="@+id/editText5"
                android:ems="10"
                android:hint="@string/passward"
                android:inputType="textPersonName" />

            <EditText
                android:id="@+id/edt_mothername"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignEnd="@+id/editText7"
                android:layout_alignRight="@+id/editText7"
                android:layout_below="@+id/editText7"
                android:ems="10"
                android:hint="@string/mother_name"
                android:inputType="textPersonName" />

            <CheckBox
                android:id="@+id/checkBox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/term_and_condition" />

            <Button
                android:id="@+id/btn_signup"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:background="@drawable/btn_all"
                android:text="@string/sign_up"
                android:textAlignment="center"
                android:textSize="19sp"
                android:padding="10dp"
                android:gravity="center"/>


        </LinearLayout>
    </ScrollView>
</android.widget.RelativeLayout>


2)sign_up.java


package com.example.store.n01;

import android.content.Intent;
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 Sign_up extends AppCompatActivity {
    EditText edit_name ,edt_mobileno ,edt_passwardsu ,edt_mothername;
    Button btn_signup ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_up);
        edit_name = (EditText)findViewById(R.id.edit_name);
        edt_mobileno = (EditText)findViewById(R.id.edt_mobileno);
        edt_passwardsu=(EditText)findViewById(R.id.edt_passwardsu);
        edt_mothername= (EditText)findViewById(R.id.edt_mothername);

        btn_signup =(Button)findViewById(R.id.btn_signup);

        btn_signup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s1 = edit_name.getText().toString();
                String s2 =edt_mobileno.getText().toString();
                String s3 =edt_passwardsu.getText().toString();
                String s4 =edt_mothername.getText().toString();

                Intent i = new Intent(getApplicationContext(),text_view.class);
                i.putExtra("name",edit_name.getText().toString());
                i.putExtra("mobileno",edt_mobileno.getText().toString());
                i.putExtra("mothername",edt_mothername.getText().toString());
                i.putExtra("passwardsu",edt_passwardsu.getText().toString());

                startActivity(i);

               // Toast.makeText(Sign_up.this, s1 +"\n"+"\n"+s2 +"\n"+ s3+"\n"+s4, Toast.LENGTH_SHORT).show();

            }
        });

    }

}




3)activity_text_view.xml

activity preview :-

activity_text_view.xml

<?xml version="1.0" encoding="utf-8"?>
<android.widget.LinearLayout 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:orientation="vertical"
     >


    <TextView
        android:id="@+id/name_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/textview" />

    <TextView
        android:id="@+id/mobileno_tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/textview" />

    <TextView
        android:id="@+id/passward_tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/textview" />

    <TextView
        android:id="@+id/mothername_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/textview" />
</android.widget.LinearLayout>


4)text_view.java

package com.example.store.n01;

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

public class text_view extends AppCompatActivity {

    TextView name_tv,mobileno_tv,passward_tv,mothername_tv;

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

        name_tv = (TextView)findViewById(R.id.name_tv);
        mobileno_tv = (TextView)findViewById(R.id.mobileno_tv);
        passward_tv= (TextView)findViewById(R.id.passward_tv);
        mothername_tv= (TextView)findViewById(R.id.mothername_tv);

        name_tv.setText(getIntent().getStringExtra("name"));
        mobileno_tv.setText(getIntent().getStringExtra("mobileno"));
        passward_tv.setText(getIntent().getStringExtra("mothername"));
        mothername_tv.setText(getIntent().getStringExtra("passwardsu"));

    }
}


it was pass a data 1st activity to other activity run


Monday, 26 February 2018

example android hello world

hello friends

today we study about our android fist example HELLO WORD ,

TO SHOW IN YOUR ANDROID PHONE  with example and setting up ANDROID STUDIO .

and also setting to your mobile to run application IN ANDROID  SMART PHONE



NOW WE START

1) SETTING UP STUDIO ,



  • REFER DOWNLOAD A JAVA UPDATE VERSION AND INSTALL IN YOUR PC OR LAPTOP .
  • GIVE PATH TO JAVA  follow link https://www.javatpoint.com/how-to-set-path-in-java


  • now download ANDROID STUDIO FROM GOOGLE ,PURIFIER NEW VERSION AT AVAILABLE IN THAT SITE  https://developer.android.com/studio/index.html
      

  • AFTER download run .it takes some time to download component so make sure to some passion , it take more than 1 hour ,


  • now start your android project with empty activity . 


EXAMPLE 


HELLO WORLD,




The Main Activity File

The main activity code is a Java file MainActivity.java. This is the actual application file which ultimately gets converted to a Dalvik executable and runs your application. Following is the default code generated by the application wizard for Hello World! application −
package com.example.helloworld;

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

public class MainActivity extends AppCompatActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
   }
}

The Layout File

The activity_main.xml is a layout file available in res/layout directory, that is referenced by your application when building its interface. You will modify this file very frequently to change the layout of your application. For your "Hello World!" application, this file will have following content related to default layout −
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent" >
   
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_centerVertical="true"
      android:padding="@dimen/padding_medium"
      android:text="@string/hello_world"
      tools:context=".MainActivity" />
      
</RelativeLayout>

Step by step:
  1. Connect your phone to computer via USB.
  2. Development option create by click on about phone> Kernel version (tap on that at list 8 time thane create a developer option . on your hend-set ) now time in a Mi and VIVO   phone not required to create option , it was automatic generated by  connect usb  to your system .
  3. Enable USB debugging on your phone: Settings -> Applications -> Development -> USB debugging.
  4. Change Run configuration in your Eclipse project: right click -> Run As -> Run Configuration




thank you

connect with us ,  comment section for more 
next section will be continue with some other example on android WIDGETS ,

B Remi Calculator

Loan Calculator Loan Calculator Loan Amount PF Cross Sell (LI % GI) No Yes EMI CARD No Ye...