Monday, April 11, 2011

DIALOG IN ANDROID / CUSTOM DIALOG

cdialog.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="200dip"
  android:orientation="vertical"
  android:padding="5dip"
  android:layout_height="fill_parent">
 
  <TextView
      android:layout_width="fill_parent"
      android:text="Dialog Title"
      android:gravity="center_vertical"
      android:layout_height="20dip">
  </TextView>
 
  <TextView
      android:layout_width="fill_parent"
      android:layout_marginTop="5dip"
      android:background="#FFFFFF"
      android:layout_height="0.5sp">
  </TextView>
 
  <TextView
      android:layout_width="fill_parent"
      android:text="Dialog Message"
      android:gravity="center_vertical"
      android:layout_height="50dip">
  </TextView>
 
  <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="OK"
      android:id="@+id/btnOk"
      android:layout_gravity="center">
  </Button>
 
</LinearLayout>
 

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnDialog"
        android:text="ShowDialog">
    </Button>

</LinearLayout>



CustomDialog.java:
package com.customdialog.home;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;

public class CustomDialog extends Dialog
{

    public CustomDialog(Context context)
    {
        super(context);
    }
   
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.cdialog);
    }
}
Home.java:

package com.customdialog.home;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Home extends Activity
{
    /** Called when the activity is first created. */
    Button btnClick;
    CustomDialog cd;
    @Override   
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        btnClick = (Button)findViewById(R.id.btnDialog);
        btnClick.setOnClickListener(new OnClickListener()
        {           
            @Override
            public void onClick(View arg0)
            {
                cd = new CustomDialog(Home.this);
                cd.show();
               
                Button btnDimiss = (Button)cd.findViewById(R.id.btnOk);
                btnDimiss.setOnClickListener(new OnClickListener()
                {                   
                    @Override
                    public void onClick(View arg0)
                    {
                        cd.dismiss();   
                    }
                });

            }
        });
    }
}


TABS IN ANDROID

In order to create the tabs we have to use the following
TabHost
TabWidget
The TabHost is the root node for the layout contain TabWidget and Frame Layout.
The TabWidget is to maintain the tabs.
The Frame Layout contains the visible view for that Tab.

tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
   
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
       
        <!-- Contain Tabs -->
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
       
        <!-- Contain Content of the Tab -->
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
           
    </LinearLayout>
</TabHost>

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>




Home.java
package com.tabsdemo.activities;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;


public class Home extends TabActivity
{
    /** Called when the activity is first created. */
    TabHost objTabHost;
    public String TAB_NAMES[] = {"tab1","tab2","tab3"};
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabs);
       
        //Getting the TabHost Object to add TabSpec
        objTabHost = getTabHost();
       
        for(int i=0 ; i
        {
            //Creation of a Tab
            TabHost.TabSpec tab = objTabHost.newTabSpec(TAB_NAMES[i]);
           
            //Associating Intent to Tab
            ComponentName oneActivity = new ComponentName("com.tabsdemo.activities", "com.tabsdemo.activities." + TAB_NAMES[i]);
            Intent intent = new Intent().setComponent(oneActivity);                       
            tab.setContent(intent);
           
            //Adding Name and Drawable to Tab
            tab.setIndicator(TAB_NAMES[i], getResources().getDrawable(R.drawable.more_tab));//("TAB"+i, R.drawable.more_tab);
           
            objTabHost.addTab(tab);
        }
       
        objTabHost.setCurrentTab(0);
    }
}


tab1.iava:
 package com.tabsdemo.activities;

import android.app.Activity;
import android.os.Bundle;

public class tab1 extends Activity
{
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //Content of the Tab1
    }
}

tab2.java:
 package com.tabsdemo.activities;

import android.app.Activity;
import android.os.Bundle;

public class tab2 extends Activity
{
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
tab3.java:
package com.tabsdemo.activities;

import android.app.Activity;
import android.os.Bundle;


public class tab3 extends Activity
{
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

If you want  more detail go to the following link:
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

PUBLISING THE APPLICATION TO ANDROID MARKET

In order to submit Android Application to Market Place we should follow some steps :

Step 1: 

We Have to generate own keystore with keystore name, password, Alias Name , Alias Password and Validity as follows
 
 
 
Open Command Prompt
Go to the drive in which JAVA is installed.
Change the directory to jdk. 
change the directory to bin.
Execute  keytool cmd.

Then execute the following command.
$ keytool -genkey -v -keystore yourkeystorename.keystore -alias alias_name_foryourkeystore  
  -keyalg RSA -keysize 2048 -validity 10000
  
   Here 10000 is the minimum validity period. If you want increase the period based 
on your requirement.
 
   on execution of this command keystore will created in your bin folder.
 
Step 2:
 
versioning the Application. 
 
-> Setting the application version  
  
   An integer value that represents the version of the application code. 
   In your application if you specify the android:versionCode as 2
   It means your application has 2 release.  
 
-> Setting the application version name.
 
     A value that represents the version of the application code, as it should be shown 
   to users. 
 
-> Specifying the Applications system api requirements. 
 
     To specify api level requirements we have to use  in our manifase.xml
 
     android:minSdkVersion :
         The minimum version of the android platform on which the application will run.
     android:targerSdkversion : 
          Specifies the API level on which the applicaion is designed to run.
     android:maxSdkVersion :
          The maximum version of the Android platform on which the application is designed to run.  
 
Step 3: 

Signing the application with the keysotre.
 
NOTE: 
Before signing test the application no of times. Check for android:debuggable in your
manifast.xml because you do not release for public in debug mode. So we have to remove 
that.
 
Go to Ecclipsc
Right Click on Your Application.
We found the option Android Tools -> Export Signed Application Package
Then follow the windows that will appear.  
 
 
 
 
  
 
The prescribed link is as follows. Here you find complete documentaion.
 
http://developer.android.com/guide/publishing/app-signing.html