Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private EditText money, procent;
- private TextView answer;
- private Button btn;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_calculator);
- init();
- btn.setOnClickListener(v -> answer());
- }
- private void init() {
- money = findViewById(R.id.money);
- procent = findViewById(R.id.procent);
- answer = findViewById(R.id.answer);
- btn = findViewById(R.id.btn);
- }
- private void answer(){
- System.out.println("===================== "+money.getText().toString());
- int qwe = Integer.parseInt(money.getText().toString());
- System.out.println(qwe);
- int asd = Integer.parseInt(procent.getText().toString());
- int Answer = qwe * asd / 100;
- answer.setText(String.valueOf(Answer));
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout 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:layout_row="2"
- tools:context=".calculator">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/first">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Procent:" />
- <EditText
- android:id="@+id/procent"
- android:layout_width="200px"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@+id/first"
- android:id="@+id/second">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="50px"
- android:text="Money:" />
- <EditText
- android:id="@+id/money"
- android:layout_width="200px"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@+id/second"
- android:id="@+id/btn"
- android:text="Go"
- />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@+id/second"
- android:layout_marginTop="150px">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="50px"
- android:text="Answer:" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/answer"/>
- </LinearLayout>
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement