Showing posts with label codejava. Show all posts
Showing posts with label codejava. 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, 7 March 2018

check box with button toast make activity in android with xml and java file

check box with button toast 
checked or unchecked

check_box.xml
check_box.java


check_box.xml preview:-



check_box.xml code :-


<?xml version="1.0" encoding="utf-8"?>
<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">

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

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

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

    <Button
        android:id="@+id/btn_checkbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="submit" />
</LinearLayout>




check_box.java code :-



package com.example.store.gried_and_list_view;

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

public class check_box extends AppCompatActivity {

    CheckBox A1 ,A2,A3;
    Button btn_checkbox ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        A1 = (CheckBox)findViewById(R.id.A1);
        A2 = (CheckBox)findViewById(R.id.A2);
        A3 = (CheckBox)findViewById(R.id.A3);

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

     
     
        //for check and unchecked indivisuale 
      /*  A1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

                if(b){
                    Toast.makeText(check_box.this, A1.getText().toString() + " is checked..", Toast.LENGTH_SHORT).show();
                }
                else {
                    Toast.makeText(check_box.this, A1.getText().toString() + " is unchecked..", Toast.LENGTH_SHORT).show();
                }

            }
        });

        A2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

                if (b){
                    Toast.makeText(check_box.this, A2.getText().toString()+"is checked", Toast.LENGTH_SHORT).show();
                }
                else {
                    Toast.makeText(check_box.this,A2.getText().toString()+ "is unchecked", Toast.LENGTH_SHORT).show();
                }
            }
        });
        A3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    Toast.makeText(check_box.this,A3.getText().toString()+ "is checked..", Toast.LENGTH_SHORT).show();
                }
                else {
                    Toast.makeText(check_box.this,A3.getText().toString()+ "is unchecked", Toast.LENGTH_SHORT).show();
                }
            }
        });
        */

        btn_checkbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s= "";
                if (A1.isChecked()){
                    s=A1.getText().toString()+"is checked ...";
                }
                if (A2.isChecked()){
                    s=s+A2.getText().toString()+"is checked ...";
                }
                if (A3.isChecked()){
                    s=s+A3.getText().toString()+"is checked ...";
                }
                Toast.makeText(check_box.this, s, Toast.LENGTH_SHORT).show();
            }
        });

    }
}


video preview for that activity:-








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


B Remi Calculator

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