Twitter Facebook Delicious Digg Stumbleupon Favorites More

Tuesday 4 September 2018

court counter app

package com.courtcounter.raj.courtcounter;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    int teamAscore = 0;
    int teamBscore = 0;
    TextView teamAtextscore, teamBtextscore;
    Button Athree, Atwo, Afree, Bthree, ABwo, Bfree;

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


    }

    public void displayforteamA(int score) {
        teamAtextscore = (TextView) findViewById(R.id.team_a_score);

        teamAtextscore.setText(String.valueOf(score));


    }


    public void displayforteamB(int score) {
        teamBtextscore = (TextView) findViewById(R.id.team_B_score);
        teamBtextscore.setText(String.valueOf(score));

    }

    public void IncreaseScore(View view) {
        int buttonId = view.getId();

        //logic for team a
        if (buttonId == R.id.increase_three_point_A) {
            teamAscore = teamAscore + 3;
            displayforteamA(teamAscore);
        }
        if (buttonId == R.id.increase_two_point_A) {
            teamAscore = teamAscore + 2;
            displayforteamA(teamAscore);
        }
        if (buttonId == R.id.freethrowTeam_A) {
            teamAscore = teamAscore + 1;
            displayforteamA(teamAscore);
        }
        //logic for team B
        if (buttonId == R.id.increase_three_pointB) {
            teamBscore = teamBscore + 3;
            displayforteamB(teamBscore);
        }
        if (buttonId == R.id.increase_two_pointB) {
            teamBscore = teamBscore + 2;
            displayforteamB(teamBscore);
        }
        if (buttonId == R.id.freethrowTeamB) {
            teamBscore = teamBscore + 1;
            displayforteamB(teamBscore);
        }


    }

    public void oClear(View view) {
        teamAscore = 0;
        teamBscore = 0;
        displayforteamA(0);
        displayforteamB(0);

    }
}
/*if (teamAscore>teamBscore)
{
    teamAtextscore.setTextColor(getResources().getColor(R.color.winnerColor));
    teamBtextscore.setTextColor(getResources().getColor(R.color.lesscolour));

}
else
{
    teamBtextscore.setTextColor(getResources().getColor(R.color.winnerColor));
    teamAtextscore.setTextColor(getResources().getColor(R.color.lesscolour));

}
*/








================================================================================================================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#263238"
    tools:context=".MainActivity">



    <LinearLayout
        android:id="@+id/containall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <!--coing for first-->

        <LinearLayout
            android:id="@+id/first"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5sp"
            android:layout_marginRight="5sp"
            android:layout_marginTop="10sp"
            android:layout_weight="1"
            android:orientation="vertical"

            >

            <TextView
                android:id="@+id/teamname"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal"
                android:text="TEAM A"
                android:textColor="#FFC107"
                android:textSize="20dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/team_a_score"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10sp"

                android:text="0"
                android:textColor="#FFC107"
                android:textSize="50sp"
                android:textStyle="bold" />

            <Button
                android:id="@+id/increase_three_point_A"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:layout_marginTop="15dp"

                android:background=" #FFC107"
                android:onClick="IncreaseScore"
                android:text="+ 3 POINTS" />

            <Button
                android:id="@+id/increase_two_point_A"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:layout_marginTop="15dp"
                android:background=" #FFC107"
                android:onClick="IncreaseScore"
                android:text="+ 2 POINTS" />

            <Button
                android:id="@+id/freethrowTeam_A"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:layout_marginTop="15dp"
                android:background=" #FFC107"
                android:onClick="IncreaseScore"
                android:text="FREE THROW" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <View
                android:layout_width="2dp"
                android:layout_height="match_parent"
                android:background="@color/colorPrimary">

            </View>

        </LinearLayout>
        <!--coding for second-->
        <LinearLayout
            android:id="@+id/second"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5sp"
            android:layout_marginRight="5sp"
            android:layout_marginTop="10sp"
            android:layout_weight="1"
            android:orientation="vertical"

            >

            <TextView
                android:id="@+id/teamnameB"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal"
                android:text="TEAM B"
                android:textColor="#FFC107"
                android:textSize="20dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/team_B_score"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10sp"

                android:text="0"
                android:textColor="#FFC107"
                android:textSize="50sp"
                android:textStyle="bold" />

            <Button
                android:id="@+id/increase_three_pointB"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:layout_marginTop="15dp"
                android:background=" #FFC107"
                android:onClick="IncreaseScore"
                android:text="+ 3 POINTS" />

            <Button
                android:id="@+id/increase_two_pointB"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:layout_marginTop="15dp"
                android:background=" #FFC107"
                android:onClick="IncreaseScore"
                android:text="+ 2 POINTS" />

            <Button
                android:id="@+id/freethrowTeamB"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:layout_marginTop="15dp"
                android:background=" #FFC107"
                android:onClick="IncreaseScore"
                android:text="FREE THROW" />

        </LinearLayout>


    </LinearLayout>

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="94dp"
        android:layout_weight="1"
        android:text="RESET"
        android:background="#FFC107"
        android:textSize="20dp"
        android:textStyle="bold"
        android:onClick="oClear"/>
</RelativeLayout>

Share:

0 comments:

Post a Comment

Search This Blog

Popular Posts

Pages

how to make crores from 1 lakh in stock markets in 1 year

how to make crores from 1 lakh in stock markets in 1 year

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab