Sunday, March 4, 2018

An Android Application : MainActivity (Advance Java programming)



The Advance java program (source code) of the above Android App made by me is written below
 ----------------------------------------------------------------------------------------------------------------------
package com.intellisoftwaresolutions.nifty;


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



public class MainActivity extends AppCompatActivity {

    private Button pbtn1,pbtn2,pbtn3,reset2;
    private TextView tvp,tvap,tvop;
    private EditText etbp,etsp,etobp,etosp,eta;
    float s1, b1,p1,s2,b2,p2;


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

        pbtn1=(Button)findViewById(R.id.pbtn1);
        pbtn2=(Button)findViewById(R.id.pbtn2);
        tvp=(TextView)findViewById(R.id.tvp);
        tvop=(TextView)findViewById(R.id.tvop);
        etbp=(EditText)findViewById(R.id.etbp);
        etsp=(EditText)findViewById(R.id.etsp);
        etobp=(EditText)findViewById(R.id.etobp);
        etosp=(EditText)findViewById(R.id.etosp);
        pbtn3=(Button)findViewById(R.id.pbtn3);
        eta=(EditText)findViewById(R.id.eta);
        tvap=(TextView)findViewById(R.id.tvap);
        reset2=(Button)findViewById(R.id.reset2);

        addListenerOnButton();

    }

    public void addListenerOnButton()
    {
        pbtn1.setOnClickListener
                (
                        new View.OnClickListener()
                        {













                            @Override
                            public void onClick(View v) {int i;
                                String value1=etbp.getText().toString();
                                String value2=etsp.getText().toString();
                                b1=Float.parseFloat(value1);
                                s1=Float.parseFloat(value2);
                                if((s1<=0.00)||(b1<=0.00)) {
                                    Toast.makeText(getApplicationContext(), "Non-Zero only", Toast.LENGTH_SHORT).show();
                                }

                                if((s1!=0.00)&&(b1!=0.00)) {
                                    p1 = (((s1 - b1) / b1) * 100) - 0.67f;
                                    i=Math.round(p1);
                                    String np = Integer.toString(i);
                                    tvp.setText(np);
                                }


                            }
                        }

                );
        pbtn3.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        float a,ap;
                        int i,ip,ia;
                        String value=eta.getText().toString();
                        a=Float.parseFloat(value);
                        if(a<=0.00) {
                            Toast.makeText(getApplicationContext(), "Non-Zero values only", Toast.LENGTH_SHORT).show();
                        }

                        if(a!=0.00)
                        {
                            ap = (((s1 - b1) / b1) * 100) - 0.67f;
                            i=Math.round(ap);
                            ia=Math.round(a);
                            ip=(i*ia)/100;
                            String np = Integer.toString(ip);
                            tvap.setText(np);
                        }


                    }
                }
        );
        pbtn2.setOnClickListener
                (
                        new View.OnClickListener()
                        {
                            @Override
                            public void onClick(View v) {
                                String value1=etobp.getText().toString();
                                String value2=etosp.getText().toString();
                                b2=Float.parseFloat(value1);
                                s2=Float.parseFloat(value2);
                                if((s2<=0.00)||(b2<=0.00))
                                {
                                    Toast.makeText(getApplicationContext(),"Non-Zero values only",Toast.LENGTH_SHORT).show();
                                }
                                if((s2!=0.00)&&(b2!=0.00)) {
                                    p2 = (s2 - b2) * 75;
                                    String np = Float.toString(p2);
                                    tvop.setText(np);
                                }

                            }
                        }

                );
        reset2.setOnClickListener(
                new View.OnClickListener()
                {@Override
                 public void onClick(View v)
                    {   etbp.setText("         ");
                        etsp.setText("         ");
                        eta.setText("    ");
                        etobp.setText("     ");
                        etosp.setText("     ");
                        String value1=etobp.getText().toString();
                        String value2=etosp.getText().toString();
                        tvop.setText("    ");
                        tvap.setText("    ");
                        tvp.setText("    ");
                    }
                }
        );
    }
}

---------------------------------------------------------------------------------------------------------------------------

Thanks
Happy Apping !

No comments:

Post a Comment

इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया - सुदर्शन फ़ाकिर

 इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया वरना क्या बात थी किस बात ने रोने ना दिया आप कहते थे कि रोने से ना बदलेंगे नसीब उमर भर आप की इस बात...