Anasayfa Mobil Android Programlama Ders 26: İdeal Kilo Hesaplama Programı Oluşturuyoruz

Android Programlama Ders 26: İdeal Kilo Hesaplama Programı Oluşturuyoruz

Android Programlama derslerimizin 26. bölümünde sizlerle birlikte ideal kilo hesaplama yapan uygulamayı oluşturmayı öğreneceğiz.

İdeal kiloyu hesaplamak için iki tane formülü kullanacağız. Birincisi BKİ (beden kitle indeksi) ve ikincisi de ideal kilo bulma formülü olacak. BKİ vücut ağırlığı ve boy ölçülerinin belirli bir matematiksel hesap ile oranlanması sonucu ortaya çıkan bir sayıdır. (BKİ= Kilo (kg) / Boy2 (m2)). İkinci ideal kilo hesaplama formülü erkek için = (boy-100)*0,9 ve bayan için = (boy-100)*0,85. BKİ erkekler ve bayanlar için biraz farklı oluyor.

Beden Kitle İndeksi

19′ dan küçük: Çok zayıf

20-25 arasında : Normal kilolu

25-30 arasında: Hafif şişman

30 ve üzerinde: Şişman (Obez)

40 ve üzerinde: Aşırı Şişman (Morbid obez)

Bu teste yaş sınırı (yaş sınırı 18-46) olacak. Ve boylara göre farklı formüleri kullanacağız.

Uygulamamızın hesaplamayı yapan pencere üç tane butondan, üç tane giriş alanlardan, iki tane Checkbox’tan ve üç TexView’den oluşacak. Butonlar üç işlem (tamam, temizle ve tavsiye) yapacaktır. TextView’un amacı ideal kiloyu BKİ ve tavsiye göstermektir. CheckBox’ların amacı erkek veya bayanı seçmek. Hazır uygulamayı buradan  indirebilirsiniz.

Yeni proje oluşturalım:

  • Project name: P0026_Idealkilo
  • Build Target: Android 4.2
  • Application name: Idealkilo
  • Package name: tr.androidApp.Idealkilo
  • Create Activity: MainActivity

main.xml’i açalım ve ekranı oluşturalım:

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“@drawable/androidwallpaper”

android:gravity=“center”

android:paddingBottom=“@dimen/activity_vertical_margin”

android:paddingLeft=“@dimen/activity_horizontal_margin”

android:paddingRight=“@dimen/activity_horizontal_margin”

android:paddingTop=“@dimen/activity_vertical_margin”

tools:context=“.MainActivity” >

 

<Button

android:id=“@+id/turk”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentTop=“true”

android:layout_centerHorizontal=“true”

android:textSize=“22sp”

android:textStyle=“bold”

android:layout_marginTop=“78dp”

android:text=“@string/turkish” />

 

<Button

android:id=“@+id/bilgi”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignLeft=“@+id/turk”

android:layout_alignRight=“@+id/turk”

android:layout_below=“@+id/turk”

android:layout_marginTop=“18dp”

android:text=“@string/info”

android:textSize=“22sp”

android:textStyle=“bold” />

</RelativeLayout>

</RelativeLayout>

Ana sayfamızda iki buton bulunacak (Başla ve Bilgi).  Başla butonuna basıldığı zaman ideal kilo hesaplama penceresini açacak. Bilgi butonu ise bize program hakkında bilgi sunacaktır.

values – > strings.xml açalım ve aşağıdaki verdiğim kodu kopyaladım:

<?xml version=“1.0” encoding=“utf-8”?>

<resources>

<string name=“app_name”>İdeal Kilo Testi</string>

<string name=“action_settings”>Settings</string>

<string name=“hello_world”>Hello world!</string>

<string name=“text”>Beden Kitle İndeksinizi (BKİ) tespit ederek

zayıf mı, şişman mı yoksa normal kiloda mı olduğunuzu öğrenebilirsiniz.

İdeal Kilonuzu Hesaplayın!

BKİ= Kilo (kg) / Boy2 (m2)

İdeal kilo hesaplama formülü erkek için = (boy-100)*0,9

ve kadın için = (boy-100)*0,85

</string>

<string name=“turkish”>Başla</string>

<string name=“erkek”>Erkek</string>

<string name=“info”>Bilgi</string>

<string name=“santim”>cm</string>

<string name=“kilo”>kilo</string>

<string name=“ya_”>yaş</string>

<string name=“bayan”>Bayan</string>

<string name=“cm”>cm</string>

<string name=“doctor”>Doktor Öz den hızlı zayıflama önerileri:

1-  Öğün atlamak, vücudu yağ depolamaya yönelik kazanma moduna geçirir.Böylelikle kalori yakımı zorlaşır.

</string>

</resources>

Layout dosyasında üç tane pencere oluşturalım baslik.xml , tavsiye.xml ve turkce.xml .

baslik.xml’i açalım ve ekranı oluşturalım:

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“@drawable/androidwallpaper”

android:paddingBottom=“@dimen/activity_vertical_margin”

android:paddingLeft=“@dimen/activity_horizontal_margin”

android:paddingRight=“@dimen/activity_horizontal_margin”

android:paddingTop=“@dimen/activity_vertical_margin”

tools:context=“.MainActivity” >

<TextView

android:id=“@+id/text”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentTop=“true”

android:layout_centerHorizontal=“true”

android:layout_marginTop=“59dp”

android:text=“@string/text”

android:textSize=“18sp”

android:textStyle=“bold” />

</RelativeLayout>

tavsiye.xml’i açalım ve ekranı oluşturalım:

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:paddingBottom=“@dimen/activity_vertical_margin”

android:paddingLeft=“@dimen/activity_horizontal_margin”

android:paddingRight=“@dimen/activity_horizontal_margin”

android:paddingTop=“@dimen/activity_vertical_margin”

tools:context=“.MainActivity” >

<TextView

android:id=“@+id/text”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentLeft=“true”

android:layout_alignParentTop=“true”

android:text=“@string/doctor”

android:textSize=“18sp”

android:textStyle=“bold” />

</RelativeLayout>

turkce.xml’i açalım ve ekranı oluşturalım:

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“@drawable/androidwallpaper”

android:paddingBottom=“@dimen/activity_vertical_margin”

android:paddingLeft=“@dimen/activity_horizontal_margin”

android:paddingRight=“@dimen/activity_horizontal_margin”

android:paddingTop=“@dimen/activity_vertical_margin”

tools:context=“.MainActivity” >

 

<CheckBox

android:id=“@+id/checkBox1”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentLeft=“true”

android:layout_alignParentTop=“true”

android:textSize=“19sp”

android:textStyle=“bold”

android:text=“@string/erkek” />

 

<CheckBox

android:id=“@+id/checkBox2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentRight=“true”

android:layout_alignParentTop=“true”

android:text=“@string/bayan”

android:textSize=“19sp”

android:textStyle=“bold” />

 

<EditText

android:id=“@+id/num1”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentLeft=“true”

android:layout_below=“@+id/checkBox1”

android:layout_marginTop=“16dp”

android:contentDescription=“Boyunuz”

android:ems=“10”

android:hint=“Boyunuz”

android:inputType=“numberDecimal”

android:textSize=“19sp”

android:textStyle=“bold” >

 

<requestFocus />

</EditText>

 

<EditText

android:id=“@+id/num2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignLeft=“@+id/num1”

android:layout_below=“@+id/num1”

android:layout_marginTop=“15dp”

android:contentDescription=“Kilonuz”

android:ems=“10”

android:hint=“Kilonuz”

android:inputType=“numberDecimal”

android:textSize=“19sp”

android:textStyle=“bold” />

 

<TextView

android:id=“@+id/text”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_above=“@+id/num2”

android:layout_alignParentRight=“true”

android:text=“@string/cm”

android:textSize=“19sp”

android:textStyle=“bold” />

 

<TextView

android:id=“@+id/textView2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignBottom=“@+id/num2”

android:layout_alignParentRight=“true”

android:textSize=“19sp”

android:textStyle=“bold”

android:text=“@string/kilo” />

 

<EditText

android:id=“@+id/num3”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignLeft=“@+id/num2”

android:layout_below=“@+id/num2”

android:layout_marginTop=“15dp”

android:contentDescription=“Yaşınız”

android:ems=“10”

android:hint=“Yaşınız”

android:inputType=“numberDecimal”

android:textSize=“19sp”

android:textStyle=“bold” />

 

<TextView

android:id=“@+id/textView3”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignBottom=“@+id/num3”

android:layout_alignParentRight=“true”

android:textSize=“19sp”

android:textStyle=“bold”

android:text=“@string/ya_” />

 

<TextView

android:id=“@+id/textView5”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignLeft=“@+id/textView4”

android:layout_below=“@+id/textView4”

android:layout_marginTop=“20dp”

android:text=“BKI”

android:textSize=“16sp”

android:textStyle=“bold” />

 

<Button

android:id=“@+id/bilgi”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignBottom=“@+id/button1”

android:layout_alignLeft=“@+id/checkBox2”

android:layout_alignParentRight=“true”

android:text=“Tavsiye”

android:textSize=“19sp”

android:textStyle=“bold” />

 

<TextView

android:id=“@+id/textView6”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignBaseline=“@+id/textView4”

android:layout_alignBottom=“@+id/textView4”

android:layout_centerHorizontal=“true”

android:textSize=“16sp”

android:textStyle=“bold” />

 

<TextView

android:id=“@+id/textView7”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_above=“@+id/button1”

android:layout_alignLeft=“@+id/textView6”

android:textSize=“16sp”

android:textStyle=“bold” />

 

<Button

android:id=“@+id/button1”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignLeft=“@+id/textView5”

android:layout_below=“@+id/textView5”

android:layout_marginTop=“43dp”

android:text=“Tamam”

android:textSize=“19sp”

android:textStyle=“bold” />

 

<Button

android:id=“@+id/button3”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignBaseline=“@+id/button1”

android:layout_alignBottom=“@+id/button1”

android:layout_centerHorizontal=“true”

android:text=“Temizle”

android:textSize=“19sp”

android:textStyle=“bold” />

<TextView

android:id=“@+id/textView8”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_below=“@+id/textView7”

android:layout_centerHorizontal=“true”

android:textAppearance=“?android:attr/textAppearanceMedium” />

 

<TextView

android:id=“@+id/textView4”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignLeft=“@+id/num3”

android:layout_below=“@+id/num3”

android:layout_marginTop=“27dp”

android:text=“Ideal Kilomu”

android:textSize=“16sp”

android:textStyle=“bold” />

 

</RelativeLayout>

Uygulamanın arka planını oluşturmak için Eclipse’te res – drawable-hdpi klasörüne aşağıdaki verdiğim resmi androidwallpaper olarak isimlendiriyor ve kopyalıyorsunuz.

androidwallpaper

Ders Sonu Notları:

Bu derste projenin xml pencereli oluşturduk ve ideal kilo hesaplamak için bazı formülleri öğrendik. Gelecek derste yeni java clasları oluşturacağız ve MainActivity.java kodla dolduracağız.