Android list view getItemAtPosition() is returning raw data

androidlistview

i have implemented a list view its working fine but when i click on the list it gives me raw data that getItemAtPosition(position) returns me.

following is the code that i am using

public class FirstTab extends Activity{

    private TabHostProvider tabProvider;
    private TabView tabView;
    private static String[] country1;
    private ListView speakerList;
    final Handler mHandler = new Handler();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Context context = getApplicationContext();
        tabProvider = new TabbarView(this);
        tabView = tabProvider.getTabHost("main");
        tabView.setCurrentView(R.layout.firsttab);
        setContentView(tabView.render(0));
        String temp[] = new String[]{"furqan","furqan1","furqan2"};
        Weather weather_data[] = new Weather[temp.length];
        for(int i = 0;i<temp.length;i++)
        {
            weather_data[i] = new Weather(R.drawable.ic_launcher, temp[i]);
        }

        WeatherAdapter adapter = new WeatherAdapter(this,R.layout.listview_item_row, weather_data);
        speakerList = (ListView)findViewById(R.id.speakerList);
        View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
        speakerList.addHeaderView(header);
        speakerList.setAdapter(adapter);

        final ViewFlipper viewflipper = (ViewFlipper) findViewById(R.id.viewflipper);
        speakerList.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(final AdapterView<?> arg0, View arg1, final int arg2,long arg3) {
                // TODO Auto-generated method stub


                String item = speakerList.getItemAtPosition(arg2).toString();
                Log.d("the  value is", item);
                        /*View item = (View) (speakerList.getItemAtPosition(arg2));
                        String item = arg0.getItemAtPosition(arg2).toString();
                        Log.d("the  value is", item);*/
                        //Toast.makeText(getApplicationContext(), arg2, 1).show();



            }

        });

    }   
}

The above is the main activity.Following is the adapter

public class weatheradapter {



    public static class WeatherAdapter extends ArrayAdapter<Weather>{

        Context context; 
        int layoutResourceId;    
        Weather data[] = null;

        public WeatherAdapter(Context context, int layoutResourceId, Weather[] data) {
            super(context, layoutResourceId, data);
            this.layoutResourceId = layoutResourceId;
            this.context = context;
            this.data = data;
        }

        static class WeatherHolder
        {
            ImageView imgIcon;
            TextView txtTitle;
        }



        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            WeatherHolder holder = null;

            if(row == null)
            {
                LayoutInflater inflater = ((Activity)context).getLayoutInflater();
                row = inflater.inflate(layoutResourceId, parent, false);

                holder = new WeatherHolder();
                holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
                holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);

                row.setTag(holder);
            }
            else
            {
                holder = (WeatherHolder)row.getTag();
            }

            Weather weather = data[position];
            holder.txtTitle.setText(weather.title);
            holder.imgIcon.setImageResource(weather.icon);

            return row;
        }


    }
}

this is the xml file

<?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"
    android:layout_gravity="center" android:gravity="center" android:background="#00FFcc">

    <ViewFlipper android:id="@+id/viewflipper" android:layout_width="fill_parent" android:layout_height="fill_parent" > 

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

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


    </ViewFlipper>

</LinearLayout>

The following is the layout for the list view

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

     <ImageView android:id="@+id/imgIcon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="15dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp" />



       <TextView android:id="@+id/txtTitle"
         android:text="@+id/txtTitle"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:textStyle="bold"
        android:textSize="22dp"
        android:textColor="#000000"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp" />

</LinearLayout>

need help thanks

Best Solution

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    Cursor c = (Cursor) parent.getAdapter().getItem(position);
    c.getString(c.getColumnIndex("col_name")));
}