Pages

Wednesday, September 19, 2012

Layout Inflator Service

Layout Inflator Service

If you want to customize any layout/View then you have to use "Layout Inflator Service"

we are learn that by listview example

If you want to change the default layout of the list view then you have to use BaseAdapter + Layout Inflator service.

Now, You have to perform following Step:-

1) Take the list view in res/main.xml file as follows:

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
            android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
   

2) Take another layout xml in res/row.xml which contain layout for each cell(row) in listview as follows:


    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

            android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         >

                    android:id="@+id/imageView1"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:src="@drawable/ic_action_search" />

                    android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_toRightOf="@id/imageView1"
             >
                            android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="35dp"
                />
                            android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="35dp"
                

                android:id="@+id/btnDelete"
                android:layout_width="wrap_content"
                android:layout_height="60dp"
                android:gravity="center"
                android:layout_alignParentRight="true"
    

3) create another class file MyBaseAdapter.Java which extend BaseAdapter class.

  • Create Constructor with Parameterized Context & ArrayList)

    override fillowing  methods of BaseAdapter getCount(),getItem(int position),getItemId(int position),getView(final int position, View convertView, ViewGroup parent)


    public class MyBaseAdapter extends BaseAdapter {
    // This is the Array of the int to get the image from the res/drawable folder
    int image[] = {R.drawable.i,R.drawable.j,R.drawable.k,R.drawable.l,R.drawable.m,R.drawable.n,R.drawable.o,       R.drawable.p,R.drawable.q,R.drawable.r,R.drawable.s,R.drawable.t,R.drawable.u,R.drawable.v,R.drawable.w};

        Context context;
        ArrayList alList;
    //This is the constructor to get the Activity Context & the information which you want to display in the ListView
        public MyBaseAdapter(Context context , ArrayList alList){
            this.alList= alList;
            this.context=contex;
        }
    //This method tell that how many row Base Adapter should create
        @Override
        public int getCount() {
            return alList.size();
        }
        @Override
        public Object getItem(int position){
            return null;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }
    //This is the inner class to hold the whole object of cell(row)of ListView
        private class Hold{
            ImageView iv;
            TextView tv1,tv2;
            Button btnDelete;
        }
    //This method create a cell(row) view & return to the ListView
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            Hold hold;
            if(convertView == null){
                LayoutInflater inflater = (LayoutInflater)                      context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(R.layout.row, null);
                hold = new Hold();
                hold.iv = (ImageView) convertView.findViewById(R.id.imageView1);
                hold.iv.setFocusable(true);
                hold.tv1 = (TextView) convertView.findViewById(R.id.textView1);
                hold.tv2 = (TextView) convertView.findViewById(R.id.textView2);
                hold.btnDelete=(Button) convertView.findViewById(R.id.btnDelete);
                convertView.setTag(hold);
            }
            else
            {
                hold = (Hold) convertView.getTag();
            }
            hold.iv.setImageResource(image[position]);
            hold.tv1.setText(alList.get(position).getName());
            hold.tv2.setText(alList.get(position).getCity());
            hold.btnDelete.setText("Delete");
            return convertView;
        }
    }
    // the above method first check view is null then & then only create new view
    otherwise it will recycle the view which is already created & get that object by tag

    4) Now,bind Listview with its object in MainActivity.java as follow:

    public class MainActivity extends Activity {
        ListView listView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            listView = (ListView) findViewById(R.id.listView1);
            ArrayList data = new ArrayList();
            data.add(new Data("Hardik", "Surat"));
            data.add(new Data("Jignesh", "Ahmedabad"));
            data.add(new Data("Umang", "Ahmedabad"));
            data.add(new Data("Dashrath", "Rajkot"));
            data.add(new Data("Amit", "Kadi"));
            data.add(new Data("Bhautik", "Surat"));
            data.add(new Data("Archit", "Baroda"));
            data.add(new Data("Maulik", "Gandhinagar"));
            MyBaseAdapter adapter = new MyBaseAdapter(this, data);
            listView.setAdapter(adapter);
        }
    }

    OutPut:-



     



Wednesday, August 8, 2012

How to Compress Image

How to Compress Image

When big size image is came to display in Imageview then java.lang.OutOfMemoryError: bitmap size exceeds VM budget error occur to handle this error we have to manage(compress) the each manage. 

For that two way is there to Compress the image

 

1) If the Height & Width is more then Imageview then we have to compress both.

2) If footprint is more then we have to compress it.

 

For that following code is possible:-

public Bitmap checkBitmap(int pos, int h, int w) {
        Bitmap bitmap = null;
        Options option = new Options();
        // this part is for Height and Width manage...
        option.inJustDecodeBounds = true;
        int sample = 16;

        BitmapFactory.decodeFile(MainActivity.strImagFileList.get(pos), option);

        if (option.outHeight > h || option.outWidth > w) {
            if (option.outHeight > option.outWidth) {
                sample = option.outHeight / h;
            } else {
                sample = option.outWidth / w;
            }
            System.out.println("Hello");
        }
        option.inSampleSize = sample;
        // this part is for compress footprint  manage...
        option.inJustDecodeBounds = false;
        bitmap = BitmapFactory.decodeFile(
                MainActivity.strImagFileList.get(pos), option);
        return bitmap;
    } 

Saturday, August 4, 2012

Manage Landscape Portrait View

Manage Landscape Portrait View

 

Now-a-days mostly android base mobile are come with touch screen so we have to manage both Landscape and Portrait view for application.

 

To Manage Landscape Portrait View in your Application Following step.

 

 1) Create the Folder(Resources) in "res"  folder as following...

2) Create main xml Following Path -res/layout/main.xml

 

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

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tvName"
            style="@style/htextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/etName"
            style="@style/heditText"
            android:layout_width="212dp"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tvClass"
            style="@style/htextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Class:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/etClass"
            style="@style/heditText"
            android:layout_width="220dp"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/tvGender"
            style="@style/htextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gender:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <RadioGroup
            android:id="@+id/rgGender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <RadioButton
                android:id="@+id/rbMale"
                style="@style/htextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Male" />

            <RadioButton
                android:id="@+id/rbFemale"
                style="@style/htextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Female" />
        </RadioGroup>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button1" />

        <Button
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button2" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button3" />

        <Button
            android:id="@+id/btn4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button4" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button5" />

        <Button
            android:id="@+id/btn6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button6" />
    </LinearLayout>

</LinearLayout>

3) Create main xml Following Path -res/layout-land/main.xml

 

    Copy the res/layout/main.xml in this main.xml

 

4) Create string xml Following Path -res/values/string.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, LandscapPotraitActivity!</string>
    <string name="app_name">LandscapPotrait</string>

    <style name="htextView">
        <item name="android:textSize">30dp</item>
        <item name="android:textColor">#41FCF9</item>
    </style>

    <style name="heditText">
        <item name="android:textSize">30dp</item>
        <item name="android:textColor">#FCFCC9</item>
    </style>

</resources>

5) Create  xml Following Path -res/values-land/string.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, LandscapPotrentActivity!</string>
    <string name="app_name">LandscapPotrent</string>

    <style name="htextView">
        <item name="android:textSize">30dp</item>
        <item name="android:textColor">#E4101B</item>
    </style>

    <style name="heditText">
        <item name="android:textSize">30dp</item>
        <item name="android:textColor">#FCFCC9</item>
    </style>

</resources>

6) LandscapPotraitActivity.java

 

package com.example.LandscapPotrait;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.RadioButton;

public class LandscapPotraitActivity extends Activity {
    /** Called when the activity is first created. */
    EditText etName, etClass;
    RadioButton rbMale, rbFemale;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        etName = (EditText) findViewById(R.id.etName);
        etClass = (EditText) findViewById(R.id.etClass);
        rbMale = (RadioButton) findViewById(R.id.rbMale);
        rbFemale = (RadioButton) findViewById(R.id.rbFemale);
        if (savedInstanceState != null) {
            etName.setText(savedInstanceState.getString("name"));
            etClass.setText(savedInstanceState.getString("class"));
            if (savedInstanceState.getBoolean("gender")) {
                rbMale.setChecked(true);
            } else
                rbFemale.setChecked(true);
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        if (etName.getText().equals("")) {
            outState.putString("name", etName.getText().toString());
        }
        if (etClass.getText().equals("")) {
            outState.putString("class", etClass.getText().toString());
        }
        if (rbMale.isChecked()) {
            outState.putBoolean("gender", true);
        } else {
            outState.putBoolean("gender", false);
        }

        super.onSaveInstanceState(outState);

    }
}

Output:-

 

Use Of Sliding Drawer

Use Of Sliding Drawer

As we are know that mobile has limited resources in terms of memory,screen etc.  so as we also had limited one screen at a time to manage so many items. For that we have to make complex layout to manage the screen item as well as display information to user. For that we manage screen two way.

 

1)Use LayoutInflater

2)Use Menu

and Another way is Use Sliding Drawer View. 

 

Sliding Drawer Contain One Button,Linear Layout.

You can put any view in this Liner Layout.

 

Layout xml File In- res/layout/activity_main.xml

activity_main.xml 

<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:background="@drawable/background" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/padding_medium"
        android:text="@string/hello_world" />

    <SlidingDrawer
        android:id="@+id/slidingDrawer1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="15dp"
        android:content="@+id/content"
        android:handle="@+id/handle" >

        <Button
            android:id="@+id/handle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Open" />

        <LinearLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="#F8F88B" >

            <ListView
                android:id="@+id/listView1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
            </ListView>
        </LinearLayout>
    </SlidingDrawer>

</RelativeLayout>

Layout xml File In- res/layout/row.xml

row.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:gravity="center"
    android:textColor="@android:color/black"
    android:textSize="25dp"
    android:textStyle="bold" >
</TextView>

Java File In -src/com.example.sliding

MainActivity.java

package com.example.slidingview;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;

public class MainActivity extends Activity {
    Button handle;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView lv = (ListView) findViewById(R.id.listView1);
        handle = (Button) findViewById(R.id.handle);
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
                R.layout.row);
        arrayAdapter.add("Hardik Patel");
        arrayAdapter.add("Umang Patel");
        arrayAdapter.add("Jignesh Desai");
        arrayAdapter.add("Urvish Patel");
        arrayAdapter.add("Archit Patel");
        arrayAdapter.add("Amit Patel");
        arrayAdapter.add("Dashrath Chavada");
        arrayAdapter.add("Rushit Joshi");
        arrayAdapter.add("Jimit Shah");
        arrayAdapter.add("Dhaval Patel");
        arrayAdapter.add("Chintan Patel");
        lv.setAdapter(arrayAdapter);
        SlidingDrawer sd = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
        sd.setOnDrawerCloseListener(new OnDrawerCloseListener() {

            public void onDrawerClosed() {
                handle.setText("Open");
            }
        });
        sd.setOnDrawerOpenListener(new OnDrawerOpenListener() {

            public void onDrawerOpened() {
                handle.setText("Close");
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Output:-









File Filtering

File Filtering

How to retrieve file with particular extension

package com.example.gridviewexample;

import java.io.File;
import java.io.FilenameFilter;

public class MyFileFilter implements FilenameFilter{

    @Override
    public boolean accept(File dir, String filename) {
       
        return (filename.endsWith(".jpeg") || filename.endsWith(".jpg") || filename.endsWith(".png")) ;
    }
}

How to Apply File Filter

strImagFileList = new ArrayList<String>();
            for (int i = 0; i < alFile.size(); i++) {
                File f = new File(alFile.get(i));
                if (new MyFileFilter().accept(f, f.getName())) {
                    strImagFileList.add(f.getAbsolutePath());
                }
            }

 

Friday, August 3, 2012

Localization

Localization

Pros

1) When the application are localized then it will become more user friendly. 

2) You can launch your application onto the market more rapidly.

3) You use resources more efficiently.

4) Your application is easier to maintain.

Process For Localization

1) Create Folder for Each Language With Naming Convention.

2) Each folder Having Same Name String & Style .xml file.

3) Each .xml File Contain Resources For Each Language.

4) You Can See As Follows.  

Note:- Hindi is available only in 4.1 and above

String.xml (For Hindi) 

Folder Name is in res "values-hi"

<resources>

    <string name="app_name">Localization</string>
    <string name="hello_world">नमस्ते हार्दिक!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="Dialog_Message">लोड हो रहा है ...</string>
    <string name="title">In hindi</string>
</resources>

String.xml (For Franch) 

Folder Name is in res "values-fr-rFR"

<resources>

    <string name="app_name">Localization</string>
    <string name="hello_world">This is fr-rFR!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="Dialog_Message">Chargement en cours ...</string>
    <string name="title">In French</string>
</resources>

String.xml (For English US) 

Folder Name is in res "values-en-rUS"

 <resources>

    <string name="app_name">Localization</string>
    <string name="hello_world">This is en-rUS!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="Dialog_Message">Loading...</string>
    <string name="title">In English US</string>
   
</resources> 

MainActivity.java

package com.example.localization;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
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
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b = (Button) findViewById(R.id.btnDialog);
      
        b.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle(R.string.title);
                builder.setMessage(R.string.Dialog_Message);
                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                   
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Note: Now Change Language of Device from Setting Menu.

Output:-




Localized Dialog:-

Note:- You Can Also Localize Image Also This Is only String Example.







Types Of Dialog Box

Types Of Dialog Box

1)SimpleProgress 

2) SimpleProgressHorizontal

 3) SimpleDialog 

3) SingleChoice

4) MultipleChoice

5) CustomAlert

7) BuiltinId Of Android Dialog Alert

Code For Each as Follows

package com.example.dialog;

import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;

public class DialogActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    Button btnCustomAlert, btnSingleChoice, btnMultipleChoice,
            btnSimpleProgress, btnSimpleProgressHorizontal, btnSimpleDialog,
            btnBuiltinIdOfAndroid;
    View view;
    AlertDialog altDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btnCustomAlert = (Button) findViewById(R.id.btnCustomAlert);
        btnCustomAlert.setOnClickListener(this);
        btnSingleChoice = (Button) findViewById(R.id.btnSingleChoice);
        btnSingleChoice.setOnClickListener(this);
        btnMultipleChoice = (Button) findViewById(R.id.btnMultipleChoice);
        btnMultipleChoice.setOnClickListener(this);
        btnSimpleProgress = (Button) findViewById(R.id.btnSimpleProgress);
        btnSimpleProgress.setOnClickListener(this);
        btnSimpleProgressHorizontal = (Button) findViewById(R.id.btnSimpleProgressHorizontal);
        btnSimpleProgressHorizontal.setOnClickListener(this);
        btnSimpleDialog = (Button) findViewById(R.id.btnSimpleDialog);
        btnSimpleDialog.setOnClickListener(this);
        btnBuiltinIdOfAndroid = (Button) findViewById(R.id.btnBuiltinIdOfAndroid);
        btnBuiltinIdOfAndroid.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        int i = v.getId();

        switch (i) {
        case R.id.btnCustomAlert:
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = li.inflate(R.layout.dialog, null);
            final EditText etName = (EditText) view.findViewById(R.id.etName);
            Button btnOk = (Button) view.findViewById(R.id.btnOk);
            Button btnCancel = (Button) view.findViewById(R.id.btnCancel);
            btnOk.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    {
                        if (etName.getText().toString().equalsIgnoreCase("")) {
                            etName.requestFocus();
                            etName.setError("Please enter your name");
                        } else {
                            AlertDialog.Builder b = new AlertDialog.Builder(
                                    DialogActivity.this);
                            b.setMessage(etName.getText().toString());
                            b.setPositiveButton("ok",
                                    new DialogInterface.OnClickListener() {

                                        @Override
                                        public void onClick(
                                                DialogInterface dialog,
                                                int which) {
                                            dialog.dismiss();
                                        }
                                    });
                            b.show();
                        }
                    }
                }
            });

            btnCancel.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    altDialog.dismiss();
                }
            });
            builder.setView(view);
            altDialog = builder.create();
            altDialog.show();

            break;
        case R.id.btnSingleChoice:
            AlertDialog.Builder builderSingle = new AlertDialog.Builder(
                    DialogActivity.this);
            builderSingle.setIcon(R.drawable.ic_launcher);
            builderSingle.setTitle("Select One Name:-");
            final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                    DialogActivity.this,
                    android.R.layout.select_dialog_singlechoice);
            arrayAdapter.add("Hardik");
            arrayAdapter.add("Archit");
            arrayAdapter.add("Jignesh");
            arrayAdapter.add("Umang");
            arrayAdapter.add("Gatti");
            builderSingle.setNegativeButton("cancel",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });

            builderSingle.setAdapter(arrayAdapter,
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String strName = arrayAdapter.getItem(which);
                            AlertDialog.Builder builderInner = new AlertDialog.Builder(
                                    DialogActivity.this);
                            builderInner.setMessage(strName);
                            builderInner.setTitle("Your Selected Item is");
                            builderInner.setPositiveButton("Ok",
                                    new DialogInterface.OnClickListener() {

                                        @Override
                                        public void onClick(
                                                DialogInterface dialog,
                                                int which) {
                                            dialog.dismiss();
                                        }
                                    });
                            builderInner.show();
                        }
                    });
            builderSingle.show();
            break;

        case R.id.btnMultipleChoice:
            AlertDialog.Builder builderMultiple = new AlertDialog.Builder(
                    DialogActivity.this);
            builderMultiple.setIcon(R.drawable.ic_launcher);
            builderMultiple.setTitle("Select item:-");
            final ArrayList<String> alSelectedItem = new ArrayList<String>();
            final String[] strItem = new String[] { "Hardik", "Archit",
                    "Jignesh", "Umang", "Gatti" };
            builderMultiple.setMultiChoiceItems(strItem, null,
                    new DialogInterface.OnMultiChoiceClickListener() {

                      @Override
                        public void onClick(DialogInterface dialog, int which,
                                boolean isChecked) {
                            if (isChecked) {
                                alSelectedItem.add(strItem[which]);
                            } else {
                                alSelectedItem.remove(strItem[which]);
                            }
                        }
                    });
            builderMultiple.setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
            builderMultiple.setPositiveButton("Ok",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (alSelectedItem.size() != 0) {
                                String strMsg = null;
                                for (int i = 0; i < alSelectedItem.size(); i++) {
                                    strMsg = strMsg + ", "
                                            + alSelectedItem.get(i);
                                }
                                AlertDialog.Builder builderInnerMul = new AlertDialog.Builder(
                                        DialogActivity.this);
                                builderInnerMul.setMessage(strMsg);
                                builderInnerMul.setIcon(R.drawable.ic_launcher);
                                builderInnerMul
                                        .setTitle("You select following item:-");
                                builderInnerMul.setPositiveButton("Ok",
                                        new DialogInterface.OnClickListener() {

                                            @Override
                                            public void onClick(
                                                    DialogInterface dialog,
                                                    int which) {
                                                dialog.dismiss();
                                            }
                                        });
                                builderInnerMul.show();
                            }
                        }
                    });
            builderMultiple.show();
            break;

        case R.id.btnSimpleProgress:
            ProgressDialog pd = new ProgressDialog(DialogActivity.this);
            pd.setTitle("Progress");
            pd.setMessage("Loading...");
            pd.setCancelable(true);
            pd.show();
            break;
        case R.id.btnSimpleProgressHorizontal:
            ProgressDialog pd1 = new ProgressDialog(DialogActivity.this);
            pd1.setTitle("Progress");
            pd1.setMessage("Loading...");

            pd1.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            pd1.show();
            break;
        case R.id.btnSimpleDialog:
            AlertDialog.Builder simpleBuilder = new AlertDialog.Builder(
                    DialogActivity.this);
            simpleBuilder.setTitle("This is Title");
            simpleBuilder.setMessage("Hello Hardik!!!");
            simpleBuilder.setIcon(R.drawable.ic_launcher);
            simpleBuilder.setPositiveButton("Ok",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
            simpleBuilder.show();
        case R.id.btnBuiltinIdOfAndroid:
            Builder aalert = new AlertDialog.Builder(this);
            ArrayAdapter<String> array = new ArrayAdapter<String>(this,
                    R.layout.text1);
            array.add("Hardik");
            array.add("Umang");
            array.add("Jignesh");
            array.add("Archit");
            array.add("Bhautik");
            array.add("Chandu");
            aalert.setTitle("Select name");
            aalert.setPositiveButton("Ok",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
            aalert.setAdapter(array, null);
            aalert.create().show();
            break;
        }

    }
}

How to retrive file from sd card(Recursive Methods)

How to retrive file from sd card(Recursive Methods)

public void walk(String path) {

        File f = new File(path);
        File[] fileList = f.listFiles();
        for (File file : fileList) {
            try {
                if (file.isDirectory()) {
                    walk(file.getAbsolutePath());
                    System.out.println("Dir: " + file.getAbsoluteFile());
                } else {
                    System.out.println("File: " + file.getAbsoluteFile());
                }
            } catch (Exception e) {
                System.out.println(e.getMessage());
                Log.i("Information", e.getMessage());
            }
        }

    }