Pass Data form listview to another activity in android?
<p>I used the below code for <strong>displaying all cities time</strong>. When i execute my code the time will displayed in a list view, <strong>now my problem is once i click any one of the country (position in list), i must pass the Country name, day, month, year and time from the list to another class (*<em>ShowAnalogClock</strong>)</em>*. In <strong>ShowAnalogClock</strong> class i will display the time which is fetched from the list view.</p>

<p><strong>main.xml</strong></p>

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

    &lt;AutoCompleteTextView
        android:id="@+id/autoCompleteZone"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:completionThreshold="1" &gt;

        &lt;requestFocus /&gt;
    &lt;/AutoCompleteTextView&gt;

    &lt;ListView
        android:id="@+id/zoneList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" &gt;
    &lt;/ListView&gt;

    &lt;TextView
        android:id="@+id/autoCompleteTextview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p><strong>timezone.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:orientation="vertical" &gt;

    &lt;TextView
        android:id="@+id/timezone_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="25dip" /&gt;

    &lt;TextView
        android:id="@+id/timezone_time"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="15dip" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>My Java code is,</p>

<p><strong>TimeZoneProjectActivity.java</strong></p>

<pre><code>package com.test.timezone;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class TimeZoneProjectActivity extends Activity {
    /** Called when the activity is first created. */
    ListView ZONE_LIST;
    AutoCompleteTextView zoneComplete_TXT;
    TimeZoneAdaptor timezoneAdaptor;
    List&lt;TimeZoneDataList&gt; timezonelist;
    String[] listItems;
    TextView auto_completeTXT;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        auto_completeTXT = (TextView) findViewById(R.id.autoCompleteTextview);
        ZONE_LIST = (ListView) findViewById(R.id.zoneList);
        zoneComplete_TXT = (AutoCompleteTextView) findViewById(R.id.autoCompleteZone);
        timezonelist = new ArrayList&lt;TimeZoneDataList&gt;();
        timezoneAdaptor = new TimeZoneAdaptor(this, R.layout.timezoneview,
                timezonelist);

        ZONE_LIST.setAdapter(timezoneAdaptor);

        ZONE_LIST.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                    int position, long arg3) {
                // TODO Auto-generated method stub
                //

                System.out.println("Clicked Position" + position);
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();

        listItems = TimeZone.getAvailableIDs();
        ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
                android.R.layout.simple_dropdown_item_1line, listItems);
        zoneComplete_TXT.setAdapter(adapter);

        TimeZone timezone = null;
        SimpleDateFormat format = new SimpleDateFormat(
                "EEE, MMM d, yyyy h:mm a");
        Date now = new Date();

        for (int index = 0; index &lt; listItems.length; ++index) {
            timezone = TimeZone.getTimeZone(listItems[index]);

            format.setTimeZone(timezone);

            timezonelist.add(new TimeZoneDataList(
                    getDiaplayName(listItems[index]), format.format(now)));

            timezone = null;
        }
    }

    private String getDiaplayName(String timezonename) {
        String displayname = timezonename;
        int sep = timezonename.indexOf('/');

        if (-1 != sep) {
            displayname = timezonename.substring(0, sep) + ", "
                    + timezonename.substring(sep + 1);
            displayname = displayname.replace("_", " ");
        }

        return displayname;
    }

    public class TimeZoneAdaptor extends ArrayAdapter&lt;TimeZoneDataList&gt; {

        List&lt;TimeZoneDataList&gt; objects = null;

        public TimeZoneAdaptor(Context context, int textViewResourceId,
                List&lt;TimeZoneDataList&gt; objects) {
            super(context, textViewResourceId, objects);

            this.objects = objects;
        }

        @Override
        public int getCount() {
            return ((null != objects) ? objects.size() : 0);
        }

        @Override
        public TimeZoneDataList getItem(int position) {
            return ((null != objects) ? objects.get(position) : null);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = convertView;

            if (null == view) {
                LayoutInflater vi = (LayoutInflater) TimeZoneProjectActivity.this
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = vi.inflate(R.layout.timezoneview, null);
            }

            TimeZoneDataList data = objects.get(position);

            if (null != data) {
                TextView textName = (TextView) view
                        .findViewById(R.id.timezone_name);
                TextView textTime = (TextView) view
                        .findViewById(R.id.timezone_time);

                textName.setText(data.name);
                textTime.setText(data.time);
            }

            return view;
        }
    }
}
</code></pre>

<p><strong>TimeZoneDataList.java</strong></p>

<pre><code>package com.test.timezone;

public class TimeZoneDataList {
    public String name;
    public String time;

    public TimeZoneDataList(String name, String time) {
        this.name = name;
        this.time = time;
    }
}
</code></pre>

<p>In which code i will add in the following block, to pass the listview content</p>

<pre><code>ZONE_LIST.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                    int position, long arg3) {
                // TODO Auto-generated method stub

                System.out.println("Clicked Position" + position);
            }
        });
</code></pre>
