Simple Android Application for the beginners
Simple Android Application for the beginners
AndroidManifest
-----------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.faisalporag.tutorialproject">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
-------------------------
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.faisalporag.tutorialproject.MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/input1"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="217dp"
android:layout_marginEnd="217dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="+"
android:padding="5dp"
android:id="@+id/textView"
android:layout_marginRight="15dp"
android:layout_alignBottom="@+id/input1"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/input2"
android:layout_alignBottom="@+id/textView"
android:layout_toRightOf="@+id/textView"
android:layout_toEndOf="@+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Equal"
android:id="@+id/equalbtn"
android:layout_marginTop="50dp"
android:layout_below="@+id/textView"
android:layout_alignRight="@+id/input1"
android:layout_alignEnd="@+id/input1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:textColor="@android:color/holo_red_dark"
android:id="@+id/result"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:id="@+id/clearbtn"
android:layout_alignTop="@+id/equalbtn"
android:layout_alignLeft="@+id/input2"
android:layout_alignStart="@+id/input2" />
</RelativeLayout>
MainActivity.java
------------------------------
package com.example.faisalporag.tutorialproject;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private EditText input1,input2;
private Button equalbtn,clearbtn;
private TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input1= (EditText) findViewById(R.id.input1);
input2= (EditText) findViewById(R.id.input2);
equalbtn= (Button) findViewById(R.id.equalbtn);
clearbtn= (Button) findViewById(R.id.clearbtn);
result= (TextView) findViewById(R.id.result);
equalbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(input1.getText().toString().equals("") && input2.getText().toString().equals(""))
{
result.setText("Please input two number");
}
else if(!input1.getText().toString().equals("") && input2.getText().toString().equals(""))
{
result.setText("Please input two number");
}
else if(input1.getText().toString().equals("") && !input2.getText().toString().equals(""))
{
result.setText("Please input two number");
}
else {
double num1 = Double.parseDouble(input1.getText().toString());
double num2 = Double.parseDouble(input2.getText().toString());
double res = num1 + num2;
result.setText("Addition Result is :" + res);
}
}
});
clearbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
input1.setFocusable(true);
//input2.setFocusable(false);
input1.setText("");
input2.setText("");
result.setText("");
}
});
}
}
/*স্বপ্নের প্রতিবিম্ব... **/
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন