Pages

Monday, 24 February 2014

Intents --- Navigation from one page to another page

It is used to navigation from one page to another page. For example if you want to click one button that will go to another page then we have to use the Onclick listener for the button and the intenet for navigation. Let us see how to code
  • First go to Res--->Layout--->activity main.xml page.
  • In that page drag and drop the button from the Palette to your page.
  • Then Double click that button. Then change the android:text="Button" />  line to this format      android:text="@string/button" />
  • Then go to String.xml in the values folder.In that String.xml file add the following line to match the button that you have previously added.
  •  <string name="button">Click Here</string> button (must be similar to third step)
  • Now Go to MainActivity.Java bu expanding the src folder. 
  1. Now Declare the button  by Button b; Then place the cursor over the Button lot of options will appear you need to choose the Import  'Button'(android.widget)
  2. Now type the onclickListener();  .then place the cursor and click the create the onclickListener() method appears.
  3. Inside the method Onclick listener type the following b=(Button)findViewById(R.id.button1);
            b.setOnClickListener(new OnClickListener() 
  4. Now go to the srcfolder and right click the src and click new---> other--->android activity.
  5. Now go to the Mainactivity.java and type Intent i=new Intent(MainActivity.this,MainActivity1.class);
                    startActivity(i);
  6. That's it.
  7. Sample code.
  8. import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;

    public class MainActivity extends Activity {

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

        private void OnClickListener() {
            // TODO Auto-generated method stub
            b=(Button)findViewById(R.id.button1);
            b.setOnClickListener(new OnClickListener() {
              
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Intent i=new Intent(MainActivity.this,MainActivity1.class);
                    startActivity(i);
                }
            });
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

    }
     
     

Your First project

There is the connectivity between .java file and main.xml file.
There are three main concepts that you need to understood
  1. Moving from one page to another page
  2. To display the information
  3. How to use Button
Intent:
             Intent is the one main thing through which we can move from one page to another page. Main concept is that where should we use it

Toast:
            Toast is the way that you can show the information in the black display while the application is running.

OnclickListener
            On click listener is used when we wish to perform the action when an Button is clicked.


  • If you want to use these Button in the java file you need to insert the button in the main.xml page
  • There is also another advantage in this eclipse is that if you have any doubt in type the code you can just press the start letter and press tab.
  • After you pressed the tab there are lot of options listed according to you code in that line

Sunday, 23 February 2014

Creating the first Android Project

Open Eclipse.exe and it will ask for the workspace, give any folder for your workspace and click ok.
Now click File --> New ---> Android Development Project.
 Next the above window will appear.In this window you have to give your project name and give next and again give next and you have to choose the icon for your app then click next.

Click the BlankActivity and click next and click finish.

After clicking Finish this page will appear.
This is the page where you can code your project.
This page has many important things that you need to know before you can develop your code
  • First look the expanded file in the left side(i.e gokulnath) Package Explorer
  • It has SRC folder.It is the source folder where you can find your java source file when you expand it
  • Next main thing is assets in which you can add the html or any javascript page to your code
  • Next is the res folder where you can insert any picture to your code.When you expand this res you will find the layout folder this is the place where you can add all the widgets to your projects such as button etc..
  • In the same res you will find the values option in this values you will see the strings.xml where you can declare all your strings used in the whole project
  • Next important thing is AndroidManifest.xml where you can add all the permissions such as internet,music and contacts etc

Android Basics ---- Eclipse

Android is one of the recent trend today.Because it is one of the top trends like Apple, Iphone etc....
We can easily develop the android application using the Eclipse.It is one of the most user friendly application that we can develop the android application
  • You can Download the eclipse here
  • Next step you need to consider is to Download the latest Java Version to your computer, because the android is working mainly based on JAVA.
  • Install the software and run it.