Showing posts with label TUTORIALS. Show all posts
Showing posts with label TUTORIALS. Show all posts
Tuesday 13 June 2017
Simple Calculator app in Android
Download Source Code
This post is similar to that of
Adding two numbers in Android
We are using different operations like subtraction, multiplication,division and also addition.
Read Working with Multiple Buttons
This example is the combination of the last two post
Adding two numbers in Android and Working with Multiple buttons,so if you have practiced that well this program is easy for you or else practice that both examples and continue this example.
We need to make the design plan.
Read Working with Multiple Buttons
This example is the combination of the last two post
Adding two numbers in Android and Working with Multiple buttons,so if you have practiced that well this program is easy for you or else practice that both examples and continue this example.
We need to make the design plan.
Create a new project and Just drag and drop and edit as per in the design.
The number 1 and Number 2 can be typed using the help of hint property.
To use the hint right click on the Plain Text and EditHint
Then register the buttons,edittext's, textview's in MainActivity.java
After that add switch case statement as in the last post and include the addition of two numbers example code and also include code for other operations also as in the image.
I think it is very easy to understand right! yeah it's so simple to develop android apps than you think if you have basic programming concepts and interest to learn!!!
Let we see the Output
When clicked ADD Button
When Clicked SUB Button
When clicked MUL button
When clicked DIV Button
Practice this example more times and do it without referring any example codes.
It will make you to have strong knowledge in working with buttons.
The number 1 and Number 2 can be typed using the help of hint property.
To use the hint right click on the Plain Text and EditHint
Then register the buttons,edittext's, textview's in MainActivity.java
After that add switch case statement as in the last post and include the addition of two numbers example code and also include code for other operations also as in the image.
I think it is very easy to understand right! yeah it's so simple to develop android apps than you think if you have basic programming concepts and interest to learn!!!
Let we see the Output
When clicked ADD Button
When Clicked SUB Button
When clicked MUL button
When clicked DIV Button
How to use Android Phone as an Emulator
Practice this example more times and do it without referring any example codes.
It will make you to have strong knowledge in working with buttons.
Working with multiple buttons in Android
Download Source Code
In this post you can learn how to work with multiple buttons , before that read how to work with buttons.
It is similar to that of working with buttons the difference is that we are going to work with multiple buttons .
We are just going to use a SWITCH case where the button id's are used in case: .
Let us start the project.
Open New Project and make a user interface by dragging dropping the buttons where you want , I recommend you to read the below two post to get grip on the Buttons.
How to display names using Button in Android
Adding two numbers in Android
After designing the user interface it will look like
Edit the names of the buttons as Button 1, Button 2, Button 3 respectively.
Right click on the button to Edit Text.
Do the same for all the buttons
After that we need to start java coding.
We need to register these three buttons and implement the interface and add unimplemented methods
After that inside the onclick method we need to write the switch condition.
This code is similar to that of switch case examples in c programs ,
the v.getId() will give you the id of the clicked button.
The other codes are similar to the previous posts.
The output will be:
How to use Android Phone as an Emulator
Working with multiple buttons in android will be useful in the upcoming examples so practice this example well and try your own ideas and practice that too.
Code of onClick() method:
public void onClick(View v){
switch (v.getId())
{
case R.id.button1:
Toast.makeText(getApplicationContext(), "Button 1 is clicked", Toast.LENGTH_LONG).show();
break;
case R.id.button2:
Toast.makeText(getApplicationContext(), "Button 2 is clicked", Toast.LENGTH_LONG).show();
break;
case R.id.button3:
Toast.makeText(getApplicationContext(), "Button 3 is clicked", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
Monday 12 June 2017
Adding two numbers in Android
Download Source Code
In this post you can learn how to add two numbers in android.Before that i recommend to read the below button example post to get an idea about working with buttons.
How to work with buttons in android
How to display names while button is clicked in android.
As in my last i have said that before starting the design we need to draw what we are going to design.
Create a New Project and drag and drop two EditText for getting inputs from the user and a Button to calculate addition operation and a TextView to display the Result.
Read this post to remove the warnings How to display names while button is clicked in android.
Next we need to start the coding part.
The registering the edittext , Textview, Button is same as the previous posts.
After that we need to declare variables to get the numbers and store the result value.
we define it in double.
double number1,number2,sum;
Then type the following code
the last lines in the code is just converting the string in to double for calculation.
Then after typing the code Run the program.
Output:
Read How to run android program in your mobile
Code of onClick() method:
public void onClick(View arg0)
{
number1=Double.parseDouble( num1.getText().toString());
number2=Double.parseDouble(num2.getText().toString());
sum=number1+number2;
result.setText(Double.toString(sum));
}
How to display names using Button in Android
Download source code
In this post we are going to display name which we are going to enter in a text field and when the button is clicked the entered name will be displayed.First we need to create a new Project in Eclipse IDE.
File ----> New ---> Android Application Project.
Give the project name and click Next--->Next-->Next--->Next---->Finish.
While creating any Project we need to make a simple design overview of that application.
It can be drawn in Paper or in Paint application.
Here I am using the first method , drawing the design in a paper.
Like this we are going to design the User Interface.
Open activity_main.xml file under DisplayingName(ProjectName)---->res---->activity_main.xml
Then find the Palette and Drag and drop the TextView element .
Then we need a place to enter the name that is called a plain text element which is found under the TextFields area.
Next we need a Button
After that we need to display the entered name for that we need text view.
Now our required elements are placed in our project, now we need to make some editing of the elements.
First we need to rename the textview, for that we need to right click on the textview--->EditText option.
Then we need to enter our desired text and click Ok.
After that you can see that the edited text will appear
Like that we can edit the Button name as Show and the last TextView to empty.
we can clear those warnings.
Go to values----> String .xml and open it.
Then type as in the image
After come to activity_main.xml and type as in the image.
Do the same for button and give the input type as text in Edit text
Now save all the errors and warnings will be gone now.
Next we need to start coding the java part for displaying the name.
Open MainActivity.java under the src folder.
Register the button and implement the interface and override the unimplemented methods as we saw in last post
Read Post
You can see the Button ID , Text Id in activity_main.xml
The coding till the last post is
We need to register the plaintext i.e edittext and text view to get the input and display the output.
Then we need to code the button part as in the image
The code is in the image.
Then Run the Program , right click on the Project Name and click Run as---> Android application
Read how to run Android app in your Mobile
The output is
input is the name of the edittext and getText() method is used to get what ever the text that the user gives inputs and settext is to set the text we want .
MainActivity.java
public class MainActivity extends Activity implements OnClickListener
{
EditText input;
TextView output;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input=(EditText)findViewById(R.id.editText1);
output=(TextView)findViewById(R.id.textView2);
Button show=(Button)findViewById(R.id.button1);
show.setOnClickListener(this);
}
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
String name=input.getText().toString();
output.setText(name);
}
{
EditText input;
TextView output;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input=(EditText)findViewById(R.id.editText1);
output=(TextView)findViewById(R.id.textView2);
Button show=(Button)findViewById(R.id.button1);
show.setOnClickListener(this);
}
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
String name=input.getText().toString();
output.setText(name);
}
This simple example will make you motivated to become an android app developer.
You find any error in this example send to my mail narain2829@gmail.com .
Subscribe to:
Posts
(
Atom
)