Showing posts with label Class 6. Show all posts
Showing posts with label Class 6. Show all posts

Class 6 (Digital Tajbhi)

Digital Tajbhi


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#AACFEC"
>

<TextView
android:id="@+id/tvCount"
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="0"
android:textStyle="bold"
android:textSize="50dp"
android:gravity="right"
android:layout_marginTop="50dp"
/>


<Button
android:id="@+id/buttonad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add One"
/>

<Button
android:id="@+id/buttonsub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sub One"
/>

<Button
android:id="@+id/buttonreset"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reset"
/>


</LinearLayout>
Java
package com.rakibshah.testblog;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {

TextView tvCount;
Button buttonad, buttonsub, buttonreset;
int count = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tvCount = findViewById(R.id.tvCount);

buttonad = findViewById(R.id.buttonad);
buttonsub = findViewById(R.id.buttonsub);
buttonreset = findViewById(R.id.buttonreset);


buttonad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

count++;
tvCount.setText(""+count);


}
});

buttonsub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {


count--;
tvCount.setText(""+count);

}
});

buttonreset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {


count = 0;
tvCount.setText(""+count);

}
});


}
}