0% found this document useful (0 votes)
7 views5 pages

Task Androied

The document contains an Android application code that implements a simple counter with addition and subtraction functionalities. It includes a MainActivity class with methods to update a TextView displaying the count and two buttons for adding and subtracting from the count. The layout is defined using XML with a ConstraintLayout, including a TextView and two buttons.

Uploaded by

mashal zirak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Task Androied

The document contains an Android application code that implements a simple counter with addition and subtraction functionalities. It includes a MainActivity class with methods to update a TextView displaying the count and two buttons for adding and subtracting from the count. The layout is defined using XML with a ConstraintLayout, including a TextView and two buttons.

Uploaded by

mashal zirak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

package com.example.

myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {


TextView counterText;
Button btnadd,btnsub;
int count;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
counterText=(TextView)findViewById(R.id.txt);
btnadd=(Button)findViewById(R.id.btn1);
btnsub=(Button)findViewById(R.id.btn2);

public void addition(View view) {


// counterText.setText("count :"+ count);
count++;
counterText.setText(String.valueOf(count));

public void subtraction(View view) {


count--;
counterText.setText(String.valueOf(count));
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="100dp"
android:textColor="#ff0000"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginBottom="100dp"
app:layout_constraintEnd_toStartOf="@id/btn2"
android:text="ADD"
android:textStyle="bold"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:onClick="addition"
/>

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBTRACT"
android:textSize="20dp"
app:layout_constraintStart_toEndOf="@+id/btn1"
android:layout_marginBottom="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:onClick="subtraction"

/>

</androidx.constraintlayout.widget.ConstraintLayout>

You might also like