Android Studioda arifmetik (+,-,*, /, ) amallarni bajaruvchi oddiy kalkulator yaratish
Download 322.85 Kb.
|
Android Studioda arifmetik , , , , amallarni bajaruvchi odd 1
- Bu sahifa navigatsiya:
- Bajardi: Elmurodov Eldor Toshkent 2023 Code
O’zbekiston Respublikasi Axborot Texnologiyalari va kommunikatsiyalarni rivojlantirish Vazirligi Muhammad Al-Xorazmiy nomidagiToshkent Axborot Texnologiyalari Universiteti. Mobil ilovalarni ishlab chiqish Labaratoriya ishi 2 Mavzu: Android Studioda arifmetik (+,-,*, /, ^) amallarni bajaruvchi oddiy kalkulator yaratish. Bajardi: Elmurodov Eldor Toshkent 2023 Code: package com.example.kalkulator; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
public class MainActivity extends AppCompatActivity implements Contract.View { TextView textView; TextView editText; TextView natija; String number=""; Contract.Presenter presenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView=findViewById(R.id.textView); editText=findViewById(R.id.editText); natija=findViewById(R.id.natija1); presenter = new Presenter(this); } @Override public void showNatija(String natija1) { natija.setText(natija1); } @Override public void editText(String text) { editText.setText(text); } @Override public void showPut(String string) { textView.setText(string); } public void plusBtnClick(View view){ Button buttonPlus = (Button) view; presenter.onclickPlus(number); textView.setText(textView.getText() + number + " + "); number = ""; editText.setText(""); } public void btnTeng(View view){ presenter.onclickTeng(editText.getText().toString()); textView.setText(""); editText.setText(""); number = ""; } public void buttonClikc(View view) { Button view1= (Button) view; if (number.length() <= 8) { number = number.concat(view1.getText().toString()); editText.setText(number); } } public String getNumber(){ return this.number; } } package com.example.kalkulator; public class Presenter implements Contract.Presenter {
@Override public void onclick() { view.getNumber(); } @Override public void onclickPlus(String number) { sum += Integer.parseInt(number); } @Override public void onclickTeng(String number) { if (number.length() != 0) { sum += Integer.parseInt(number); view.showNatija("Natija: " + sum + ""); sum = 0; } } } package com.example.kalkulator; public interface Contract {
}
void onclick(); void onclickPlus(String number1); void onclickTeng(String number); } } xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:padding="20dp" android:background="#E6D4D4"> android:layout_height="match_parent" android:orientation="vertical"> android:layout_height="0dp" android:layout_weight="3" android:gravity="center|right|top" android:orientation="vertical" android:padding="30dp"> android:hint="number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30dp" android:layout_margin="10dp"/> android:hint="number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30dp" android:layout_margin="10dp" /> android:hint="natija" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:textSize="30dp" /> android:layout_height="0dp" android:layout_weight="3.2" android:gravity="center" android:background="#2B1C1C"> android:id="@+id/btn1" android:onClick="buttonClikc" android:text="1" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" tools:ignore="OnClick" /> android:onClick="buttonClikc" android:id="@+id/btn2" android:text="2" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn1"/> android:onClick="buttonClikc" android:id="@+id/btn3" android:text="3" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn2"/> android:onClick="buttonClikc" android:id="@+id/btn4" android:text="4" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_below="@id/btn1"/> android:onClick="buttonClikc" android:id="@+id/btn5" android:text="5" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn1" android:layout_below="@id/btn2"/> android:onClick="buttonClikc" android:id="@+id/btn6" android:text="6" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn5" android:layout_below="@id/btn3"/> android:onClick="buttonClikc" android:id="@+id/btn7" android:text="7" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_below="@id/btn4"/> android:onClick="buttonClikc" android:id="@+id/btn8" android:text="8" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn7" android:layout_below="@id/btn5" /> android:onClick="buttonClikc" android:id="@+id/btn9" android:text="9" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn8" android:layout_below="@id/btn6"/> android:onClick="plusBtnClick" android:id="@+id/btn10" android:text="+" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_below="@id/btn7"/> android:onClick="buttonClikc" android:id="@+id/btn11" android:text="0" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn10" android:layout_below="@id/btn8"/> android:onClick="btnTeng" android:id="@+id/btn12" android:text="-" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn11" android:layout_below="@id/btn9"/> android:onClick="btnTeng" android:id="@+id/btn13" android:text="/" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_below="@id/btn10"/> android:onClick="btnTeng" android:id="@+id/btn14" android:text="*" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn13" android:layout_below="@id/btn11"/> android:onClick="btnTeng" android:id="@+id/btn15" android:text="=" android:textSize="40dp" android:layout_width="110dp" android:layout_height="70dp" android:layout_toRightOf="@id/btn14" android:layout_below="@id/btn12"/> Download 322.85 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling