Advertisement
mmayoub

Counter, MainActivity.java

Oct 15th, 2021
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. package com.example.myapplication0710;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.TextView;
  7.  
  8. import androidx.appcompat.app.AppCompatActivity;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.     int count;
  12.     TextView tv;
  13.     @Override
  14.     protected void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         setContentView(R.layout.activity_main);
  17.  
  18.         count=0;
  19.         tv = findViewById(R.id.tvCount);
  20.     }
  21.  
  22.     public void handleClick(View v) {
  23.         count++;
  24.         tv.setText(tv.getText().toString()+1);
  25.  
  26.  
  27.         if (count > 10) {
  28.           nextActivity(null);
  29.           count=0;
  30.             tv.setText(count+"");
  31.         }
  32.     }
  33.  
  34.     public void handleResetClick(View view) {
  35.         count=0;
  36.         tv.setText(count+"");
  37.     }
  38.  
  39.     public void nextActivity(View view) {
  40.         Intent intent;
  41.         intent = new Intent(this,MainActivity2.class);
  42.  
  43.         intent.putExtra("COUNT_VALUE",count);
  44.  
  45.         startActivity(intent);
  46.         //finish();
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement