Yangi formatda davom etish uchun: https://uzfor.net/view.php?act=post&id=82801
Postga havola
Tayota [667] [off]
Kimda qanday idea bor ?
Birga dastur tuzamiz (aideda) qóldan kelgancha...
15 kun 10 soat 35 daqiqa 33 soniyadan keyin yozdi:
Barchaga salom. Mana ancha bolibdi tepadaga post qoldirganimga ammo hech kimdan nido chiqmadi. Shuning uchun ózim mini kalkulyator tuzishga qaror qildim demak avvalo korinishni qilibolamiz
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<LinearLayout
android:id="@+id/ekran"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#FDFDFD"
android:layout_alignParentTop="true"
android:padding="7dp">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon1"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon2"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon3"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon4"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon5"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
</LinearLayout>
<LinearLayout
android:padding="1dp"
android:id="@+id/raqamlar"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom|center"
android:background="#FFFFFF">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="C"
android:layout_width="wrap_content"
android:background="#72B0C0"
android:textColor="#FFFFFF"
android:textStyle="bold|normal"
android:layout_marginRight="2dp"
android:id="@+id/tozalash"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="×"
android:layout_width="wrap_content"
android:textColor="#000000"
android:background="#D8D8D8"
android:textStyle="bold|normal"
android:layout_marginRight="2dp"
android:id="@+id/kopaytiruv"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="÷"
android:layout_width="wrap_content"
android:textColor="#000000"
android:background="#D8D8D8"
android:textStyle="bold|normal"
android:layout_marginRight="2dp"
android:id="@+id/boliv"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="D"
android:layout_width="wrap_content"
android:background="#B8554F"
android:textStyle="bold|normal"
android:textColor="#FFFFFF"
android:id="@+id/ochirish"
android:padding="10dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="1"
android:layout_width="wrap_content"
android:textColor="#000000"
android:background="#D8D8D8"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/bir"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="2"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/ikki"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="3"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/uch"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="-"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/ayruv"
android:padding="10dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="4"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/tort"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="5"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/besh"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="6"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/olti"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="+"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/qoshuv"
android:padding="10dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="7"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/yetti"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="8"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/sakkiz"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="9"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/toqqiz"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="0"
android:layout_width="wrap_content"
android:textColor="#000000"
android:background="#D8D8D8"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/nol"
android:padding="10dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="="
android:layout_width="match_parent"
android:background="#141414"
android:textStyle="bold|normal"
android:textColor="#F9F9F9"
android:layout_marginTop="2dp"
android:id="@+id/barobar"
android:padding="10dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
package uz.kalkulyator;
//kerakli liblarni ulaymiz
import android.app.*;
import android.os.*;
import android.util.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import java.io.*;
public class MainActivity extends Activity
{
//widgetlarni olamiz
TextView maydon1, maydon2, maydon3, maydon4, maydon5;
LinearLayout raqamlar, ekran;
Button tozalash, kopaytiruv, boluv, ochirish, bir, ikki, uch, ayruv, tort, besh, olti, qoshuv, yetti, sakkiz, toqqiz, nol, barobar;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//idlarga kirishga ruxsat olamiz
maydon1 = findViewById(R.id.maydon1);
maydon2 = findViewById(R.id.maydon2);
maydon3 = findViewById(R.id.maydon3);
maydon4 = findViewById(R.id.maydon4);
maydon5 = findViewById(R.id.maydon5);
raqamlar = findViewById(R.id.raqamlar);
ekran = findViewById(R.id.ekran);
tozalash = findViewById(R.id.tozalash);
kopaytiruv = findViewById(R.id.kopaytiruv);
boluv = findViewById(R.id.boliv);
ochirish = findViewById(R.id.ochirish);
bir = findViewById(R.id.bir);
ikki = findViewById(R.id.ikki);
uch = findViewById(R.id.uch);
ayruv = findViewById(R.id.ayruv);
tort = findViewById(R.id.tort);
besh = findViewById(R.id.besh);
olti = findViewById(R.id.olti);
qoshuv = findViewById(R.id.qoshuv);
yetti = findViewById(R.id.yetti);
sakkiz = findViewById(R.id.sakkiz);
toqqiz = findViewById(R.id.toqqiz);
nol = findViewById(R.id.nol);
barobar = findViewById(R.id.barobar);
//ekran razmerini olib kerakli amallarni bajaramiz
DisplayMetrics displaymetr = new DisplayMetrics();
WindowManager wm = (WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(displaymetr);
int ekranwidth = displaymetr.widthPixels;
int ekranheight = displaymetr.heightPixels;
int ekranheightyarim = ekranheight / 2;
int ekranwidthyarim = (ekranwidth / 4) - 2;
int ekranbesh = (ekranheightyarim / 5) - 2;
int fontsize = ekranwidth / 22;
int maydonfontsize = fontsize;
maydon1.setTextSize(22);
maydon2.setTextSize(22);
maydon3.setTextSize(22);
maydon4.setTextSize(22);
maydon5.setTextSize(22);
ekran.setMinimumHeight(ekranheightyarim);
raqamlar.setMinimumHeight(ekranheightyarim);
//tugmalarni width razmerini órnatamiz
tozalash.setWidth(ekranwidthyarim);
kopaytiruv.setWidth(ekranwidthyarim);
boluv.setWidth(ekranwidthyarim);
ochirish.setWidth(ekranwidthyarim);
bir.setWidth(ekranwidthyarim);
ikki.setWidth(ekranwidthyarim);
uch.setWidth(ekranwidthyarim);
tort.setWidth(ekranwidthyarim);
besh.setWidth(ekranwidthyarim);
olti.setWidth(ekranwidthyarim);
yetti.setWidth(ekranwidthyarim);
sakkiz.setWidth(ekranwidthyarim);
toqqiz.setWidth(ekranwidthyarim);
nol.setWidth(ekranwidthyarim);
qoshuv.setWidth(ekranwidthyarim);
qoshuv.setWidth(ekranwidthyarim);
ayruv.setWidth(ekranwidthyarim);
//tugmalarni height razmerini òrnatamiz
tozalash.setHeight(ekranbesh);
kopaytiruv.setHeight(ekranbesh);
boluv.setHeight(ekranbesh);
ochirish.setHeight(ekranbesh);
bir.setHeight(ekranbesh);
ikki.setHeight(ekranbesh);
uch.setHeight(ekranbesh);
tort.setHeight(ekranbesh);
besh.setHeight(ekranbesh);
olti.setHeight(ekranbesh);
yetti.setHeight(ekranbesh);
sakkiz.setHeight(ekranbesh);
toqqiz.setHeight(ekranbesh);
nol.setHeight(ekranbesh);
barobar.setHeight(ekranbesh);
qoshuv.setHeight(ekranbesh);
qoshuv.setHeight(ekranbesh);
ayruv.setHeight(ekranbesh);
//tugmalarni matn kattaligini (fontsize) òrnatamiz
tozalash.setTextSize(fontsize);
kopaytiruv.setTextSize(fontsize);
boluv.setTextSize(fontsize);
ochirish.setTextSize(fontsize);
bir.setTextSize(fontsize);
ikki.setTextSize(fontsize);
uch.setTextSize(fontsize);
tort.setTextSize(fontsize);
besh.setTextSize(fontsize);
olti.setTextSize(fontsize);
yetti.setTextSize(fontsize);
sakkiz.setTextSize(fontsize);
toqqiz.setTextSize(fontsize);
nol.setTextSize(fontsize);
barobar.setTextSize(fontsize);
qoshuv.setTextSize(fontsize);
qoshuv.setTextSize(fontsize);
ayruv.setTextSize(fontsize);
maydon1.setTextSize(maydonfontsize);
maydon2.setTextSize(maydonfontsize);
maydon3.setTextSize(maydonfontsize);
maydon4.setTextSize(maydonfontsize);
maydon5.setTextSize(maydonfontsize);
//tugmalar bosilganda roy beradigan hodisalarni qilamiz
tozalash.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
});
ochirish.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
Toast.makeText(getApplicationContext(), "O`chirish hozircha ishlamayapti", Toast.LENGTH_LONG).show();
}
});
kopaytiruv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn4 = maydon4.getText().toString();
String matn5 = maydon5.getText().toString();
if (matn1 != ""){
maydon2.setText("×");
try {
if (matn4 != "") {
maydon1.setText("" + matn5);
maydon2.setText("×");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
} catch (Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
});
boluv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn4 = maydon4.getText().toString();
String matn5 = maydon5.getText().toString();
if (matn1 != ""){
maydon2.setText("÷");
try {
if (matn4 != "") {
maydon1.setText("" + matn5);
maydon2.setText("÷");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
} catch (Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
});
ayruv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn4 = maydon4.getText().toString();
String matn5 = maydon5.getText().toString();
if (matn1 != ""){
maydon2.setText("-");
try {
if (matn4 != "") {
maydon1.setText("" + matn5);
maydon2.setText("-");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
} catch (Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
});
qoshuv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn4 = maydon4.getText().toString();
String matn5 = maydon5.getText().toString();
if (matn1 != ""){
maydon2.setText("+");
try {
if (matn4 != "") {
maydon1.setText("" + matn5);
maydon2.setText("+");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
} catch (Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
});
barobar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
try{
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
if (matn3 != "") {
Integer son1 = Integer.parseInt("" + matn1);
Integer son2 = Integer.parseInt("" + matn3);
maydon4.setText("=");
double sona1 = son1;
double sonb2 = son2;
double res;
switch(matn2){
case "+":
res = sona1 + sonb2;
maydon5.setText("" + res);
break;
case "-":
res = sona1 - sonb2;
maydon5.setText("" + res);
break;
case "×":
res = sona1 * sonb2;
maydon5.setText("" + res);
break;
case "÷":
res = sona1 / sonb2;
maydon5.setText("" + res);
break;
default:
res = 0;
}
}
} catch(Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
bir.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "1");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "1");
}
}
}
});
ikki.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "2");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "2");
}
}
}
});
uch.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "3");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "3");
}
}
}
});
tort.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "4");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "4");
}
}
}
});
besh.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "5");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "5");
}
}
}
});
olti.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "6");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "6");
}
}
}
});
yetti.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "7");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "7");
}
}
}
});
sakkiz.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "8");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "8");
}
}
}
});
toqqiz.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "9");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "9");
}
}
}
});
nol.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "0");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "0");
}
}
}
});
}
public void son(String a) {
Toast.makeText(getApplicationContext(), a, Toast.LENGTH_LONG).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="uz.kalkulyator" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
android:resizeableActivity = "true">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
15 kun 10 soat 37 daqiqa 6 soniyadan keyin yozdi:
Dasturga screen va dasturga namuna(apk fayl) va tayyor kodlar eslatib ótaman kodlar aideda yozilgan.
Birga dastur tuzamiz (aideda) qóldan kelgancha...
15 kun 10 soat 35 daqiqa 33 soniyadan keyin yozdi:
Barchaga salom. Mana ancha bolibdi tepadaga post qoldirganimga ammo hech kimdan nido chiqmadi. Shuning uchun ózim mini kalkulyator tuzishga qaror qildim demak avvalo korinishni qilibolamiz
Main.xml
main.xml kodlari (+/-)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<LinearLayout
android:id="@+id/ekran"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#FDFDFD"
android:layout_alignParentTop="true"
android:padding="7dp">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon1"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon2"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon3"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon4"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/maydon5"
android:textSize="18sp"
android:textColor="#000000"
android:typeface="serif"/>
</LinearLayout>
<LinearLayout
android:padding="1dp"
android:id="@+id/raqamlar"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom|center"
android:background="#FFFFFF">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="C"
android:layout_width="wrap_content"
android:background="#72B0C0"
android:textColor="#FFFFFF"
android:textStyle="bold|normal"
android:layout_marginRight="2dp"
android:id="@+id/tozalash"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="×"
android:layout_width="wrap_content"
android:textColor="#000000"
android:background="#D8D8D8"
android:textStyle="bold|normal"
android:layout_marginRight="2dp"
android:id="@+id/kopaytiruv"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="÷"
android:layout_width="wrap_content"
android:textColor="#000000"
android:background="#D8D8D8"
android:textStyle="bold|normal"
android:layout_marginRight="2dp"
android:id="@+id/boliv"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="D"
android:layout_width="wrap_content"
android:background="#B8554F"
android:textStyle="bold|normal"
android:textColor="#FFFFFF"
android:id="@+id/ochirish"
android:padding="10dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="1"
android:layout_width="wrap_content"
android:textColor="#000000"
android:background="#D8D8D8"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/bir"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="2"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/ikki"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="3"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/uch"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="-"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/ayruv"
android:padding="10dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="4"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/tort"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="5"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/besh"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="6"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/olti"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="+"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/qoshuv"
android:padding="10dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="7"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/yetti"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="8"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/sakkiz"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="9"
android:background="#D8D8D8"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/toqqiz"
android:padding="10dp"/>
<Button
android:layout_height="wrap_content"
android:text="0"
android:layout_width="wrap_content"
android:textColor="#000000"
android:background="#D8D8D8"
android:layout_marginRight="2dp"
android:textStyle="bold|normal"
android:layout_marginTop="2dp"
android:id="@+id/nol"
android:padding="10dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:gravity="center|center_vertical">
<Button
android:layout_height="wrap_content"
android:text="="
android:layout_width="match_parent"
android:background="#141414"
android:textStyle="bold|normal"
android:textColor="#F9F9F9"
android:layout_marginTop="2dp"
android:id="@+id/barobar"
android:padding="10dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
mainactivity.java kodlari (+/-)
package uz.kalkulyator;
//kerakli liblarni ulaymiz
import android.app.*;
import android.os.*;
import android.util.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import java.io.*;
public class MainActivity extends Activity
{
//widgetlarni olamiz
TextView maydon1, maydon2, maydon3, maydon4, maydon5;
LinearLayout raqamlar, ekran;
Button tozalash, kopaytiruv, boluv, ochirish, bir, ikki, uch, ayruv, tort, besh, olti, qoshuv, yetti, sakkiz, toqqiz, nol, barobar;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//idlarga kirishga ruxsat olamiz
maydon1 = findViewById(R.id.maydon1);
maydon2 = findViewById(R.id.maydon2);
maydon3 = findViewById(R.id.maydon3);
maydon4 = findViewById(R.id.maydon4);
maydon5 = findViewById(R.id.maydon5);
raqamlar = findViewById(R.id.raqamlar);
ekran = findViewById(R.id.ekran);
tozalash = findViewById(R.id.tozalash);
kopaytiruv = findViewById(R.id.kopaytiruv);
boluv = findViewById(R.id.boliv);
ochirish = findViewById(R.id.ochirish);
bir = findViewById(R.id.bir);
ikki = findViewById(R.id.ikki);
uch = findViewById(R.id.uch);
ayruv = findViewById(R.id.ayruv);
tort = findViewById(R.id.tort);
besh = findViewById(R.id.besh);
olti = findViewById(R.id.olti);
qoshuv = findViewById(R.id.qoshuv);
yetti = findViewById(R.id.yetti);
sakkiz = findViewById(R.id.sakkiz);
toqqiz = findViewById(R.id.toqqiz);
nol = findViewById(R.id.nol);
barobar = findViewById(R.id.barobar);
//ekran razmerini olib kerakli amallarni bajaramiz
DisplayMetrics displaymetr = new DisplayMetrics();
WindowManager wm = (WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(displaymetr);
int ekranwidth = displaymetr.widthPixels;
int ekranheight = displaymetr.heightPixels;
int ekranheightyarim = ekranheight / 2;
int ekranwidthyarim = (ekranwidth / 4) - 2;
int ekranbesh = (ekranheightyarim / 5) - 2;
int fontsize = ekranwidth / 22;
int maydonfontsize = fontsize;
maydon1.setTextSize(22);
maydon2.setTextSize(22);
maydon3.setTextSize(22);
maydon4.setTextSize(22);
maydon5.setTextSize(22);
ekran.setMinimumHeight(ekranheightyarim);
raqamlar.setMinimumHeight(ekranheightyarim);
//tugmalarni width razmerini órnatamiz
tozalash.setWidth(ekranwidthyarim);
kopaytiruv.setWidth(ekranwidthyarim);
boluv.setWidth(ekranwidthyarim);
ochirish.setWidth(ekranwidthyarim);
bir.setWidth(ekranwidthyarim);
ikki.setWidth(ekranwidthyarim);
uch.setWidth(ekranwidthyarim);
tort.setWidth(ekranwidthyarim);
besh.setWidth(ekranwidthyarim);
olti.setWidth(ekranwidthyarim);
yetti.setWidth(ekranwidthyarim);
sakkiz.setWidth(ekranwidthyarim);
toqqiz.setWidth(ekranwidthyarim);
nol.setWidth(ekranwidthyarim);
qoshuv.setWidth(ekranwidthyarim);
qoshuv.setWidth(ekranwidthyarim);
ayruv.setWidth(ekranwidthyarim);
//tugmalarni height razmerini òrnatamiz
tozalash.setHeight(ekranbesh);
kopaytiruv.setHeight(ekranbesh);
boluv.setHeight(ekranbesh);
ochirish.setHeight(ekranbesh);
bir.setHeight(ekranbesh);
ikki.setHeight(ekranbesh);
uch.setHeight(ekranbesh);
tort.setHeight(ekranbesh);
besh.setHeight(ekranbesh);
olti.setHeight(ekranbesh);
yetti.setHeight(ekranbesh);
sakkiz.setHeight(ekranbesh);
toqqiz.setHeight(ekranbesh);
nol.setHeight(ekranbesh);
barobar.setHeight(ekranbesh);
qoshuv.setHeight(ekranbesh);
qoshuv.setHeight(ekranbesh);
ayruv.setHeight(ekranbesh);
//tugmalarni matn kattaligini (fontsize) òrnatamiz
tozalash.setTextSize(fontsize);
kopaytiruv.setTextSize(fontsize);
boluv.setTextSize(fontsize);
ochirish.setTextSize(fontsize);
bir.setTextSize(fontsize);
ikki.setTextSize(fontsize);
uch.setTextSize(fontsize);
tort.setTextSize(fontsize);
besh.setTextSize(fontsize);
olti.setTextSize(fontsize);
yetti.setTextSize(fontsize);
sakkiz.setTextSize(fontsize);
toqqiz.setTextSize(fontsize);
nol.setTextSize(fontsize);
barobar.setTextSize(fontsize);
qoshuv.setTextSize(fontsize);
qoshuv.setTextSize(fontsize);
ayruv.setTextSize(fontsize);
maydon1.setTextSize(maydonfontsize);
maydon2.setTextSize(maydonfontsize);
maydon3.setTextSize(maydonfontsize);
maydon4.setTextSize(maydonfontsize);
maydon5.setTextSize(maydonfontsize);
//tugmalar bosilganda roy beradigan hodisalarni qilamiz
tozalash.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
});
ochirish.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
Toast.makeText(getApplicationContext(), "O`chirish hozircha ishlamayapti", Toast.LENGTH_LONG).show();
}
});
kopaytiruv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn4 = maydon4.getText().toString();
String matn5 = maydon5.getText().toString();
if (matn1 != ""){
maydon2.setText("×");
try {
if (matn4 != "") {
maydon1.setText("" + matn5);
maydon2.setText("×");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
} catch (Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
});
boluv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn4 = maydon4.getText().toString();
String matn5 = maydon5.getText().toString();
if (matn1 != ""){
maydon2.setText("÷");
try {
if (matn4 != "") {
maydon1.setText("" + matn5);
maydon2.setText("÷");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
} catch (Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
});
ayruv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn4 = maydon4.getText().toString();
String matn5 = maydon5.getText().toString();
if (matn1 != ""){
maydon2.setText("-");
try {
if (matn4 != "") {
maydon1.setText("" + matn5);
maydon2.setText("-");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
} catch (Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
});
qoshuv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn4 = maydon4.getText().toString();
String matn5 = maydon5.getText().toString();
if (matn1 != ""){
maydon2.setText("+");
try {
if (matn4 != "") {
maydon1.setText("" + matn5);
maydon2.setText("+");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
}
} catch (Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
});
barobar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
try{
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
if (matn3 != "") {
Integer son1 = Integer.parseInt("" + matn1);
Integer son2 = Integer.parseInt("" + matn3);
maydon4.setText("=");
double sona1 = son1;
double sonb2 = son2;
double res;
switch(matn2){
case "+":
res = sona1 + sonb2;
maydon5.setText("" + res);
break;
case "-":
res = sona1 - sonb2;
maydon5.setText("" + res);
break;
case "×":
res = sona1 * sonb2;
maydon5.setText("" + res);
break;
case "÷":
res = sona1 / sonb2;
maydon5.setText("" + res);
break;
default:
res = 0;
}
}
} catch(Exception e){
maydon1.setText("");
maydon2.setText("");
maydon3.setText("");
maydon4.setText("");
maydon5.setText("");
Toast.makeText(getApplicationContext(), "Qoldiqli son mumkin emas!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
bir.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "1");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "1");
}
}
}
});
ikki.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "2");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "2");
}
}
}
});
uch.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "3");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "3");
}
}
}
});
tort.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "4");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "4");
}
}
}
});
besh.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "5");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "5");
}
}
}
});
olti.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "6");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "6");
}
}
}
});
yetti.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "7");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "7");
}
}
}
});
sakkiz.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "8");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "8");
}
}
}
});
toqqiz.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "9");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "9");
}
}
}
});
nol.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
String matn1 = maydon1.getText().toString();
String matn2 = maydon2.getText().toString();
String matn3 = maydon3.getText().toString();
String matn4 = maydon4.getText().toString();
if (matn2 == "") {
maydon1.setText(matn1 + "0");
} else {
if (matn4 == "") {
maydon3.setText(matn3 + "0");
}
}
}
});
}
public void son(String a) {
Toast.makeText(getApplicationContext(), a, Toast.LENGTH_LONG).show();
}
}
androidmanifest.xml kodlari (+/-)
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="uz.kalkulyator" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
android:resizeableActivity = "true">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
15 kun 10 soat 37 daqiqa 6 soniyadan keyin yozdi:
Dasturga screen va dasturga namuna(apk fayl) va tayyor kodlar eslatib ótaman kodlar aideda yozilgan.