|
|
bet | 2/3 | Sana | 22.06.2022 | Hajmi | 335,05 Kb. | | #690205 |
|
public class MainActivity extends AppCompatActivity {
private EditText inputText;
private Button nateja;
private int sum;
private LinearLayout ijobiy;
private LinearLayout salbiy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get ids
salbiy = findViewById(R.id.salbiyNatijaId);
ijobiy = findViewById(R.id.ijobiyNatijaId);
inputText = findViewById(R.id.inputTextId);
nateja = findViewById(R.id.buttonId);
nateja.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sum = Integer.parseInt(inputText.getText().toString());
if (sum >= 10000000) {
ijobiy.setVisibility(View.VISIBLE);
salbiy.setVisibility(View.GONE);
} else if (sum < 1000000) {
salbiy.setVisibility(View.VISIBLE);
ijobiy.setVisibility(View.GONE);
} else {
Toast.makeText(MainActivity.this, "Ma'lumot yuq", Toast.LENGTH_SHORT).show();
}
}
});
}
}
XML ko’rinishi:
xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#FFEB0B"
android:orientation="vertical"
tools:context=".MainActivity">
<Space
android:layout_width="match_parent"
android:layout_height="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/dars_4"
android:textColor="#000"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="match_parent"
android:layout_height="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/baliqchilik"
android:textColor="#FF5722"
android:textSize="24sp"
android:textStyle="italic" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:text="@string/hisobot"
android:textColor="#C4000000"
android:textSize="18sp"
android:textStyle="normal" />
<Space
android:layout_width="match_parent"
android:layout_height="8dp" />
<EditText
android:id="@+id/inputTextId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:hint="@string/hisob"
android:inputType="numberDecimal"
android:padding="16dp"
android:textSize="18sp"
android:typeface="serif"
tools:ignore="Autofill" />
<Space
android:layout_width="match_parent"
android:layout_height="16dp" />
<Button
android:id="@+id/buttonId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:background="@drawable/buttonbackground"
android:padding="10dp"
android:text="@string/hisobotButton"
android:textColor="#FFEB3B"
android:textSize="20sp" />
<
Do'stlaringiz bilan baham: |
|
|