simplyeasylearning

Sunday 26 April 2015

Creating Pop Up Menu in Android

Introdution
This article explains PopUp menus in Android. Android Studio is used to create the sample.

A PopUp menu is a type of menu that contains a menu and displys that menu below the anchor text if space is available. If the space is not available then it displays it above the Anchor text. It appears untill when you do not click on the pop-up menu text.



For this you need to create an XML file inside "res/menu/popup" like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
     <item        
       android:id="@+id/one"
     
android:title="Android"/>
    <item        android:id="@+id/two"        android:title="BlackBerry"/>    <item        android:id="@+id/three"        android:title="Apple"/> 
</menu>Step 1
Create a project like this:


Clipboard04
Step 2
Create an XML file with this:
<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"
    tools:context=".MainActivity"
    android:background="#fdacbd">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="110dp"
        android:layout_marginTop="80dp"
        android:text="Show Popup" />

</RelativeLayout>Step 3
Create another XML file with this:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/one"
        android:title="Android"/>
    <item
        android:id="@+id/two"
        android:title="BlackBerry"/>
    <item
        android:id="@+id/three"
        android:title="Apple"/>
</menu>

Step 4

Create a Java class file and with 
the following.
 
In this you create the id of the button on which you pop up the menu. Now you will crate the instance of the PopUp menu, then you will poulete.

package com.popupmenu;
 
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Toast;
public class MainActivity extends Activity {
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                //Creating the instance of PopupMenu
                PopupMenu popupMenu = new PopupMenu(MainActivity.this, button);
                //Inflating the Popup using xml file
                popupMenu.getMenuInflater().inflate(R.menu.popup, popupMenu.getMenu());
                //registering popup with OnMenuItemClickListener
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        Toast.makeText(MainActivity.this,"Button Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
                        return true;
                    }
                });
                popupMenu.show();//showing popup menu
            }
        });//closing the setOnClickListener method
    }
}Step 5

Android Manifest.xml file
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.popupmenu"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.popupmenu.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>

Step 6
 
Popup menu

Clipboard06Clipboard02

Downloading And Installing Android Studio...

We have already covered the details about the Android Studio in the previous post, don't worry if you missed that click here if you want to have a look.

One thing I want to share with you that this IDE (Integrated Development Environment ) is designed specially for the development of android apps. One can use it on operating Systems like WINDOWS, MAC OS and LINUX.The minimum required RAM for installing this IDE is 2GB but 4GB of RAM is Recommended by Google.You must have atleast 500 MB of free disk space in your computer to install it.


How To Download And Install


The installation of this IDE is demonstrated step by step in the official website of it.
So please refer here .
In case you have any problem or query comment in box below.

Why You Should Learn Java Programming Language?


Duke learning Java 
Today In This Post I Will Tell you why it is important to learn JAVA.
Here is my list of 10 reason, which I tell anyone who ask my opinion about learning Java, and whether Java is best programming language in terms of opportunities, development and community support.


1) Java is Easy to learn
Many would be surprised to see this one of the top reason of learning Java, or considering it as best programming language, but it is. If you have steep learning curve, it would be difficult to get productive in short span of time, which is the case with most of professional project. Java has fluent English like syntax with minimum magic characters e.g. Generics angle brackets, which makes it easy to read Java program and learn quickly. Once a programmer is familiar with initial hurdles with installing JDK and setting up PATH and understand How Classpath works, it's pretty easy to write program in Java.
2) Java is an Object Oriented Programming Language
Another reason, which made Java popular is that it's an Object Oriented Programming language. Developing OOPS application is much easier, and it also helps to keep system modular, flexible and extensible. Once you have knowledge of key OOPS concept like Abstraction, Encapsulation, Polymorphism and Inheritance, you can use all those with Java. Java itself embodies many best practices and design pattern in it's library. Java is one of the few close to 100% OOPS programming language. Java also promotes use of SOLID and Object oriented design principles in form of open source projects like Spring, which make sure your object dependency is managed well by using dependency Injection principle.
3) Java has Rich API
One more reason of Java programming language's huge success is it's Rich API and most importantly it's highly visible, because come with Java installation. When I first started Java programming, I used to code Applets and those days Applets provides great animation capability, which amazes new programmer like us, who are used to code in Turbo C++ editor. Java provides API for I/O, networking, utilities, xml parsing, database connection, and almost everything. Whatever left is covered by open source libraries like Apache Commons, Google Guava and others.
4) Powerful development tools e.g. Eclipse , Netbeans
Believe it or not, Eclipse and Netbeans has played huge role to make Java one of the best programming language. Coding in IDE is pleasure, especially if you have coded in DOS Editor or Notepad. They not only helps in code completion but also provides powerful debugging capability, which is essential for real world development. Integrated Development Environment (IDE) made Java development much easier, faster and fluent. It's easy to search, refactor and read code using IDEs. Apart from IDE, Java platform also has several other tools e.g.. Maven and ANT for building Java applications, decompilers, JConsole, Visual VM for monitoring Heap usage etc.
5) Great collection of Open Source libraries
Open source libraries ensures that Java should be used everywhere. Apache, Google, and other organization has contributed lot of great libraries, which makes Java development easy, faster and cost effective. There are framework like Spring, Struts, Maven, which ensures that Java development follows best practices of software craftsmanship, promotes use of design patterns and assisted Java developers to get there job done. I always recommend to search for a functionality in Google, before writing your own code. There is good chance that, it's already coded, tested and available for ready to use.
6) Wonderful community support
Community is the biggest strength of Java programming language and platform. No matter, How good a language is, it wouldn't survive, if there is no community to support, help and share there knowledge. Java has been very lucky, it has lots of active forums, Stackoverflow, open source organizations and several Java user group to help everything. There is community to help beginners, advanced and even expert Java programmers. Java actually promotes taking and giving back to community habit. Lots of programmers, who use open source, contribute as commiter, tester etc. Expert programmer provides advice FREE at various Java forums and stackoverflow. This is simply amazing and gives lot of confidence to a newbie in Java.
7) Java is FREE
People like FREE things, Don't you? So if a programmer want to learn a programming language, or a organization wants to use a technology, COST is an important factor. Since Java is free from start, i.e. you don't need to pay anything to create Java application. This FREE thing also helped Java to become popular among individual programmers, and among large organizations. Availability of Java programmers is another big think, which makes organization to choose Java for there strategic development.
8) Excellent documentation support - Javadocs
When I first saw Javadoc, I was amazed. It's great piece of documentation, which tells lot of things about Java API. I think without Javadoc documentation, Java wouldn't be as popular, and it's one of the main reason, Why I think Java is best programming language. Not every one has time and intention to look at code to learn what a method do or how to use a class. Javadoc made learning easy, and provide an excellent reference while coding in Java. With advent of IDE, you don't even need to look Javadoc explicitly in browser, but you can get all information in your IDE window itself.
9) Java is Platform Independent
In 1990s, this was the main reason of Java's popularity. Idea of platform independence is great, and Java's tag line "write once run anywhere" was enticing enough to attract lots of new development in Java. This is still one of the reason of Java being best programming language, most of Java applications are developed in Windows environment and run in UNIX platform.
10) Java is Everywhere
Yes, Java is everywhere, it's on desktop, it's on mobile, it's on card, almost everywhere and so is Java programmers. I think Java programmer out number any other programming language professional. Though I don't have any data to back this up, but it's based on experience. This huge availability of Java programmers, is another reason, why organization prefer to choose Java for new development than any other programming language.

Android Studio . How it works?

Android Studio


Android Studio is the integral development environment used for development of Android Apps.
It is based upon the IntelliJ Idea development environment and it is the Official development tool for Android Application development for Google play.

Android studio is based upon the concept of gradle.



So what is gradle in Android Studio ?
Gradle is nothing but a system that helps in the management of the following-

i.repository management.
ii.Build Management
iii.Version Management.
iv. Application Signing of App.


Thus the gradle helps in each and every task for our projects which we build using Android Studio. It is also called as the Control version System (CVS) for android.

Through the help of Android Studio we are able to visually create our application that includes layouts like Buttons, Radio Buttons, Check Boxes, Spinners etc.




When we use Android studio we are going to use JRE or JAVA as one component and android Architecture as Another Component.

We can use collections, Utility Classes from java and we can also use Android specific classes within Android Studio.

In the next post the installation of the IDE is demonstrated click here to download and install Android Studio.

Android Architecture in details ...

 

Linux Kernel-


In the linux kernel  we have libraries and android runtime that helps to work with different concepts.
For example SqlLite is a library to store data within the App. We can have media libraries to interact with Videos, Audios and Pictures etc. We also have a very important library called as WEBKIT.


What is WEBKIT in Android?

Webkit is an browser engine powering safari, Google Chrome and Android Internet browser.


Android Runtime-


Android Runtime is a component which takes care of the core services like Google MAP, Location Service and also provides a runtime for running our apps on Google's  Android Operating System.

Android gives every required functions to a App like Memory Management, Device Mangment and other jobs which are the application requisition. Its the runtime's responsibility to interact with whom the App requiring.

The runtime environment actually targets different architectures which exist on different phones. The runtime is able to understand and push the native code according to Architecture of  the phone.


Application framework-


Application framework is a layer through which different applications can interact from various activities with the phone. Every application can interact with defferent kinds of frameworks like notification framework, View framework and telephonic fraework and others.
These frameworks are the basic building blocks for android architecture. These frameworks contains reusable codes, libraries, controls that any application can use for interaction.

Application-

Application layer is the top layer within android architecture.this layer contains two types of application.
1. Inbuilt application
2.User defined Application

1.Inbuilt applications-
Inbuilt apps like Telephony, SMS and browser etc.
They interact with the application framework but they are the integral part of the android system.

2.User Defined Applications- 

 These are the apps which are developed by the end user or the third party developer like Facebook Whatsapp or Twitter etc. They also interact with the application framework and work on the same manner as Inbuilt Applications

Thursday 20 November 2014

How to Create a Web View in Android Application

WEB VIEW :-
A WebView is used to dispaly web pages or to display some online content in your activity. It can either display remote web pages or load static HTML data. For this you need to give permission to the Android menifest.xml file. For that we need to first use the getsettings() method to get the object that handles settings of the WebView. You need to set the setJavaScriptEnables() to true to enable the JavaScript because JavaScript is disabled for the WebView.



Step 1

Create an XML file and write this:
<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
        android:background="#81a3d0">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button"
            android:text="www.google.com"/>

</RelativeLayout>Step 2Create another XML file with the following:
 
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <WebView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/webView"
            android:layout_gravity="center">

            </WebView>

</LinearLayout>Step 3Create a Java class file and write this:
package com.webviewexample;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button=(Button)findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i=new Intent(MainActivity.this,Web.class);
         startActivity(i);
            }
        });


    }
}Step 4Create another Java class and write this:
 
<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
        android:background="#81a3d0">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button"
            android:text="www.google.com"/>

</RelativeLayout>Step 4Change the Android menifest,xml file so that it is like this:

 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webviewexample"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="16" />

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.webviewexample.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>
        <activity
                android:name=".Web">

        </activity>
    </application>
</manifest>
Step 5
Clipboard04.jpgStep 6

Clipboard02.jpg

Popular Posts

Total Visitors

TutorialsHub. Powered by Blogger.

Contributors

Tutorials

Search This Blog