Monday, 22 October 2012

ANDROID - Dialogs Demo


1)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:background="#9932CC"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btnAlertDialog"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:gravity="center"
        android:text="Alert Dialog" />

    <Button
        android:id="@+id/btnProgressDialog"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Progress Dialog" />

    <Button
        android:id="@+id/btnDatePickerDialog"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Date Picker Dialog" />

    <Button
        android:id="@+id/btnTimePickerDialog"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Time Picker Dialog" />

</LinearLayout>

2)Activity:


package com.venkool;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;

public class DialogsDemoActivity extends Activity {
      /** Called when the activity is first created. */

      Button btnAlertDialog, btnProgressDialog, btnDatePickerDialog,
                  btnTimePickerDialog;

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            btnAlertDialog = (Button) findViewById(R.id.btnAlertDialog);

            btnProgressDialog = (Button) findViewById(R.id.btnProgressDialog);

            btnDatePickerDialog = (Button) findViewById(R.id.btnDatePickerDialog);

            btnTimePickerDialog = (Button) findViewById(R.id.btnTimePickerDialog);

            btnAlertDialog.setOnClickListener(new OnClickListener() {

                  public void onClick(View v) {

                        AlertDialog.Builder alert = new AlertDialog.Builder(
                                    DialogsDemoActivity.this);

                        alert.setMessage("Do you Want to Continuee ...")
                                    .setPositiveButton("Yes",
                                                new DialogInterface.OnClickListener() {

                                                      @Override
                                                      public void onClick(DialogInterface dialog,
                                                                  int which) {
                                                            // TODO Auto-generated method stub

                                                            Toast.makeText(getApplicationContext(),
                                                                        "You Clicked => Yes", 5000)
                                                                        .show();
                                                      }
                                                })
                                    .setNegativeButton("No",
                                                new DialogInterface.OnClickListener() {

                                                      @Override
                                                      public void onClick(DialogInterface dialog,
                                                                  int which) {
                                                            // TODO Auto-generated method stub

                                                            Toast.makeText(getApplicationContext(),
                                                                        "You Clicked => No", 5000)
                                                                        .show();
                                                      }
                                                }).show();

                  }

            });

            btnProgressDialog.setOnClickListener(new OnClickListener() {

                  @Override
                  public void onClick(View v) {

                        ProgressDialog progress = new ProgressDialog(
                                    DialogsDemoActivity.this);
                        progress.setMessage("Loading...");
                        progress.show();
                  }
            });

            btnDatePickerDialog.setOnClickListener(new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                        // TODO Auto-generated method stub

                        Calendar c = Calendar.getInstance();
                        int cYear = c.get(Calendar.YEAR);
                        int cMonth = c.get(Calendar.MONTH);
                        int cDay = c.get(Calendar.DAY_OF_MONTH);

                        DatePickerDialog date = new DatePickerDialog(
                                    DialogsDemoActivity.this, dateListener, cYear, cMonth,
                                    cDay);
                        date.show();
                  }
            });

            btnTimePickerDialog.setOnClickListener(new OnClickListener() {

                  @Override
                  public void onClick(View v) {

                        Calendar c = Calendar.getInstance();
                        int cHour = c.get(Calendar.HOUR_OF_DAY);
                        int cMinute = c.get(Calendar.MINUTE);

                        TimePickerDialog time = new TimePickerDialog(
                                    DialogsDemoActivity.this, timeListener, cHour, cMinute,
                                    false);
                        time.show();
                  }
            });
      }

      OnDateSetListener dateListener = new OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                        int dayOfMonth) {

                  int month = monthOfYear + 1;

                  Toast.makeText(
                              DialogsDemoActivity.this,
                              "Selected Date is" + dayOfMonth + "-" + month + "-"
                                          + year, 5000).show();
            }
      };

      OnTimeSetListener timeListener = new OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

                  Toast.makeText(DialogsDemoActivity.this,
                              "Selected Time is :" + hourOfDay + ":" + minute, 5000)
                              .show();
            }
      };
}


3)Download this Project Click Here


Demo :


 



Cisco (Banjara Hills) - Hyderabad

Cisco
8-2-618/2
Level 3
Reliance Humsafar Building
Road No 11, Banjara Hills
Hyderabad - 500 034
Andhra Pradesh
India
Phone: +91 40 4031 7000
Fax: +91 40 4031 7777

Cisco (Esquire Center) - Bangalore

Cisco
Level 1, Block B, Esquire Center
9, M. G. Road
Bangalore - 560001
Karnataka
India
Phone: +91 80 4136 9300

Cisco (SEZ Unit) - Bangalore

Cisco
SEZ Unit, Cessna Business Park, Kadubeesanahalli Village,
Varthur Hobli, Sarjapur - Marathahalli Outer ring road,
Bangalore - 560087
Karnataka
India

Cisco (Akkithimanahalli) - Bangalore

Cisco
Divyasree Chambers
B Wing
O'Shaugnessy Road
Akkithimanahalli
Bangalore - 560027
Karnataka
India
Phone: +91 80 4103 3000
Fax: +91 80 2223 016

Cisco (Kadubeesanhalli) - Bangalore

Cisco
Salarpuria Hallmark Bldg A
133, Kadubeesanhalli
Panatoor Gram Panchayat
Outer Ring Road
Bangalore - 560037
Karnataka
India
Phone: +91 80 4182 2000
Fax: +91 80 4182 2050

Cisco (M G Road) - Bangalore

Cisco
2nd floor
Brigade South Parade
10, M.G. Road
Bangalore - 560 001
Karnataka
India
Phone: +91 80 4159 3000
Fax: +91 80 2532 7282

Cisco (Raheja Tower) - Chennai

Cisco
Unit No 511, 5th floor
Raheja Tower
177, Annai Salai (Mount Road)
Chennai
Tamil Nadu
India

Cisco (Bandra East) - Mumbai

Cisco
6th floor
IL & FS Financial Centre
Plot C-22, G-Block
Bandra Kurla Complex
Bandra (East)
Mumbai - 400051
Maharashtra
India
Phone: +91 22 4043 4000
Fax: +91 22 2653 3703

Cisco (Pride Silicon Plaza) - Pune

Cisco
Pride Silicon Plaza
106-A, Ground Floor
Senapati Bapat Road
Next to Chatushringi Temple
Pune - 411016
Maharashtra
India

Cisco (Godrej Waterside) - Calcutta

Cisco
Office 2, Tower-1
Godrej Waterside,
Plot No. 5
Calcutta, West Bengal 70009
India
Phone: +91 33 4400 1011
Fax: +91 33 3984 5265

Cisco (BPTP I Park) - Gurgaon

Cisco
1st Floor, BPTP I Park,
#15 Udyog Vihar Phase-IV
Gurgaon, Haryana 122015
India
Phone: +91 124 440 2000
Fax: +91 124 440 2006

L&T Infotech (Whitefield) - Bangalore

L&T Infotech
Plot No. 25 - 31,
EPIP 2nd Phase
KIADB Industrial Area,
Whitefield,
Bengaluru 560066
T +91 80 6624 2424
F +91 80 2841 3555

L&T Infotech (Manapakkam) - Chennai

L&T Infotech
Mount Poonamallee Road,
Manapakkam, Chennai 600 089
T +91 44 2252 9100
F +91 44 2252 3514


L&T Infotech (Hootagalli) - Mysore

L&T Infotech
KIADB Industrial Area
Hebbal, Hootagalli,
Mysore 570 018
T +91 821 6616161
F +91 821 2402813

L&T Infotech (Hinjewadi) - Pune

L&T Infotech
2nd & 3rd floor, IT-6 Building,
Flagship Infrastructure Pvt. Ltd.,
IT & ITES, SEZ, Survey No.154/6,
Rajiv Gandhi Infotech Park,
Hinjewadi, Phase-1,
Pune 411 005

L&T Infotech (Shivaji Nagar) - Pune

L&T Infotech
Godrej Eternia-A,
4, Mumbai-Pune Road,
Shivaji Nagar,
Pune 411 005
T + 91 20 6641 6262
F + 91 20 6609 3325

L&T Infotech (Airoli) - Mumbai

L&T Infotech
2nd Office Floor, Building No. 3,
Serene Properties SEZ,
Airoli, Thane Belapur Road,
Navi Mumbai 400 708
T + 91 22 6119 4444

L&T Infotech (Shil Mahape Road) - Mumbai

L&T Infotech
Plot No. EL - 200,
TTC Electronic Zone,
Shil - Mahape Road,
Navi Mumbai 400 701
T +91 22 6795 4545
F +91 22 2761 2580

L&T Infotech (Saki Vihar Road) - Mumbai

L&T Infotech
South Block
Gate No.2, Saki Vihar Road,
Powai, Mumbai 400072
T +91 22 6694 8484
F +91 22 2858 1615 / 1592

L&T Infotech (Saki Vihar Road) - Mumbai

L&T Technology Center
Gate No.5, Saki Vihar Road,
Powai, Mumbai 400072
T +91 22 6776 6776
F +91 22 6776 6004

L&T Infotech (Ballard Estate) - Mumbai

L&T Infotech
L&T House, Ballard Estate
Mumbai 400 001, India
T +91 22 6752 5656
F +91 22 6752 5858

Win IT (Kondapur) - Hyderabad

Win IT Software
6thFloor, Block-B, West Wing,
Laxmi Cyber Towers, Whitefields,
Kondapur, Hyderabad,
500084, Andhra Pradesh, India.
Phone : +91-40-67308800

Friday, 19 October 2012

ANDROID - Custom ListView with Image and Text

Demo:

1)Custom ListView Activity:

package com.venky.customlistviewwithimageandtextview;

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

public class CustomListViewwithImageandTextViewActivity extends Activity {
      /** Called when the activity is first created. */
      final int[] my = { R.drawable.a1, R.drawable.a2, R.drawable.a3,
                  R.drawable.a4, R.drawable.a5, R.drawable.a6, R.drawable.a7,
                  R.drawable.a8 };

      ListView lvList;

      String[] name, phone;

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            lvList = (ListView) findViewById(R.id.lvList);

            name = getResources().getStringArray(R.array.name);
            phone = getResources().getStringArray(R.array.phno);

            lvList.setAdapter(new MyAdapter(my, name, phone,
                        CustomListViewwithImageandTextViewActivity.this));

      }
}  

                    

2)MyAdapter:

package com.venky.customlistviewwithimageandtextview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
      String[] name, phone;
      Context context;
      int[] my;

      public MyAdapter(int[] my, String[] name, String[] phone,
                  CustomListViewwithImageandTextViewActivity myContext) {
            // TODO Auto-generated constructor stub

            this.my = my;
            this.name = name;
            this.phone = phone;
            context = myContext;
      }

      @Override
      public int getCount() {
            // TODO Auto-generated method stub
            return name.length;
      }

      @Override
      public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
      }

      @Override
      public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
      }

      @Override
      public View getView(int position, View v, ViewGroup parent) {
            // TODO Auto-generated method stub
            v = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.style,
                        null);
            TextView tvName = (TextView) v.findViewById(R.id.tvName);
            TextView tvPhone = (TextView) v.findViewById(R.id.tvPhone);
            ImageView ivImage = (ImageView) v.findViewById(R.id.ivImage);
            tvName.setText(name[position]);
            tvPhone.setText(phone[position]);
            ivImage.setImageResource(my[position]);
            return v;
      }

}

3)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:background="#5F04B4"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/lvList"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </ListView>

</LinearLayout>


4)style.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="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/ivImage"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="center" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tvName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/tvPhone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:textSize="20dp" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>


5)Add this code your strings.xml:

<string-array name="name">
        <item>Nagendram</item>
        <item>Srinivasa Rao</item>
        <item>Saraswathi</item>
        <item>Mounika</item>
        <item>Chandra Shekar</item>
        <item>Subba Rao</item>
        <item>Venkateswarlu</item>
        <item>Hari</item>
    </string-array>

    <string-array name="phno">
        <item>0123456789</item>
        <item>1234567890</item>
        <item>2345678901</item>
        <item>3456789012</item>
        <item>9876543210</item>
        <item>8765432109</item>
        <item>7654321098</item>
        <item>1237894560</item>
    </string-array>



6)Download this Project Click Here