MainActivity java package com xo vaznconvertor


Download 493.34 Kb.
Sana17.06.2023
Hajmi493.34 Kb.
#1536676
Bog'liq
XOconvertor


MainActivity.java

package com.xo.vaznconvertor;
import android.os.*;
import android.support.v7.app.AppCompatActivity;
import android.content.*;
import java.util.ArrayList;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.ArrayAdapter;
import android.view.View;

public class MainActivity extends AppCompatActivity {

private double z1 = 0;

private ArrayList vaqt = new ArrayList<>();

private LinearLayout linear1;
private TextView textview1;
private LinearLayout linear2;
private Button ansBtn;
private EditText x1;
private Spinner y1;
private TextView x2;
private Spinner y2;

@Override


protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.activity_main);
initialize(_savedInstanceState);
initializeLogic();
}

private void initialize(Bundle _savedInstanceState) {

linear1 = (LinearLayout) findViewById(R.id.linear1);
linear2 = (LinearLayout) findViewById(R.id.linear2);
ansBtn = (Button) findViewById(R.id.ansBtn);
x1 = (EditText) findViewById(R.id.x1);
y1 = (Spinner) findViewById(R.id.y1);
x2 = (TextView) findViewById(R.id.x2);
y2 = (Spinner) findViewById(R.id.y2);

ansBtn.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View _view) {
z1 = Double.parseDouble(x1.getText().toString());
if (y1.getSelectedItemPosition() == 0) {
if (y2.getSelectedItemPosition() == 0) {
x2.setText(x1.getText().toString());
}
else {
if (y2.getSelectedItemPosition() == 1) {
x2.setText(String.valueOf(z1 * 60));
}
else {
if (y2.getSelectedItemPosition() == 2) {
x2.setText(String.valueOf(z1 * 3600));
}
else {
if (y2.getSelectedItemPosition() == 3) {
x2.setText(String.valueOf(z1 * 3600000));
}
// else {
// Toast.makeText(getApplicationContext(), "Tanlang");
// }
}
}
}
}
else {
if (y1.getSelectedItemPosition() == 1) {
if (y2.getSelectedItemPosition() == 0) {
x2.setText(String.valueOf(z1 / 60));
}
else {
if (y2.getSelectedItemPosition() == 1) {
x2.setText(x1.getText().toString());
}
else {
if (y2.getSelectedItemPosition() == 2) {
x2.setText(String.valueOf(z1 * 60));
}
else {
if (y2.getSelectedItemPosition() == 3) {
x2.setText(String.valueOf(z1 * 60000));
}
// else {
// Toast tanlang = Toast.makeText(getApplicationContext(), "Tanlang");
// }
}
}
}
}
else {
if (y1.getSelectedItemPosition() == 2) {
if (y2.getSelectedItemPosition() == 0) {
x2.setText(String.valueOf(z1 / 3600));
}
else {
if (y2.getSelectedItemPosition() == 1) {
x2.setText(String.valueOf(z1 / 60));
}
else {
if (y2.getSelectedItemPosition() == 2) {
x2.setText(x1.getText().toString());
}
else {
if (y2.getSelectedItemPosition() == 3) {
x2.setText(String.valueOf(z1 * 1000));
}
// else {
// Toast tanlang = Toast.makeText(getApplicationContext(), "Tanlang");
// }
}
}
}
}
else {
if (y1.getSelectedItemPosition() == 3) {
if (y2.getSelectedItemPosition() == 0) {
x2.setText(String.valueOf(z1 / 3600000));
}
else {
if (y2.getSelectedItemPosition() == 1) {
x2.setText(String.valueOf(z1 / 60000));
}
else {
if (y2.getSelectedItemPosition() == 2) {
x2.setText(String.valueOf(z1 / 1000));
}
else {
if (y2.getSelectedItemPosition() == 3) {
x2.setText(x1.getText().toString());
}
// else {
// Toast tanlang = Toast.makeText(getApplicationContext(), "Tanlang");
// }
}
}
}
}
// else {
// Toast tanlang = Toast.makeText(getApplicationContext(), "Tanlang");
// }
}
}
}
}
});
}

private void initializeLogic() {


vaqt.add((int)(0), "soat");
vaqt.add((int)(1), "minut");
vaqt.add((int)(2), "second");
vaqt.add((int)(3), "milli second ");
y1.setAdapter(new ArrayAdapter(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, vaqt));
((ArrayAdapter)y1.getAdapter()).notifyDataSetChanged();
y2.setAdapter(new ArrayAdapter(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, vaqt));
((ArrayAdapter)y2.getAdapter()).notifyDataSetChanged();
}

@Override


protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
switch (_requestCode) {

default:
break;


}
}

}

activity_main.xml



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"
tools:context=".MainActivity"
android:background="@drawable/bgimg__2_"
android:gravity="center_horizontal|center_vertical"
android:padding="8dp">

android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="77dp"
android:layout_marginRight="77dp"
android:layout_marginTop="7dp"
android:gravity="center"
android:orientation="horizontal"
android:padding="8dp">

android:id="@+id/x1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:inputType="numberSigned"
android:padding="8dp"
android:singleLine="true"
android:textColor="#39D8C0"
android:textColorHint="#39D8C0"
android:textSize="25sp" />

android:id="@+id/y1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:spinnerMode="dialog" />


android:id="@+id/linear2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginLeft="77dp"
android:layout_marginRight="77dp"
android:layout_marginTop="7dp"
android:orientation="horizontal"
android:gravity="center"
android:padding="8dp">

android:id="@+id/x2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:padding="8dp"
android:textColor="#39D8C0"
android:textSize="25sp" />

android:id="@+id/y2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:spinnerMode="dialog" />



Download 493.34 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling