Вы находитесь на странице: 1из 2

import android.app.

Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener{


/** Called when the activity is first created. */
Button btncalculate,btnclose;
EditText etname, etsss, ettax, etpagibig, etphilhealth;
Spinner spposition;
TextView tvrate;
double rate,salary,sss,tax,pagibig,philhealth,deduction;
String sname,sposition;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
spposition=(Spinner)findViewById(R.id.idposition);
btncalculate=(Button)findViewById(R.id.idcalculate);
etname=(EditText)findViewById(R.id.idfname);
ettax=(EditText)findViewById(R.id.idtax);
etsss=(EditText)findViewById(R.id.idsss);
etpagibig=(EditText)findViewById(R.id.idpagibig);
etphilhealth=(EditText)findViewById(R.id.idphilhealth);
tvrate=(TextView)findViewById(R.id.idrate);
btncalculate.setOnClickListener(this);
spposition.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {

if
(spposition.getSelectedItem().toString().equalsIgnoreCase("Manager"))
rate=Double.parseDouble("30000");
else if
(spposition.getSelectedItem().toString().equalsIgnoreCase("Regular"))
rate=Double.parseDouble("20000");
else if
(spposition.getSelectedItem().toString().equalsIgnoreCase("Casual"))
rate=Double.parseDouble("8000");
tvrate.setText(String.valueOf(rate));
}
public void onNothingSelected(AdapterView<?> arg0) {

});
}
public void onClick(View v) {

switch (v.getId()){
case R.id.idcalculate:
tax=Double.parseDouble(ettax.getText().toString());

sname=etname.getText().toString();
sposition=spposition.getSelectedItem().toString();
Bundle b = new Bundle();
b.putString("k_name", sname);
b.putString("k_position", sposition);
b.putString("k_salary", String.valueOf(salary));
Intent i=new Intent(MainActivity.this, DisplayOutput.class);
i.putExtras(b);
startActivity(i);
break;

}
}
}

Вам также может понравиться