get selected object from listview

I will find a way to get a selected item in my list view and then to cast in my object type, but i get an error i think is to big to see whats is wrong. Can you help me ?

My code :

mListMenu = (ListView) findViewById(R.id.listView_tracks);
        mListMenu.setAdapter(new TracksListAdapter(this, TrackManager.getAllTrackFromTel(new DataBaseHelper(this))));
        mListMenu.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapter, View arg1,
                    int position, long arg3) {
                    Track selectedItem = (Track) adapter.getAdapter().getItem(position);
                    Intent intent = new Intent();
                     Bundle bundle = new Bundle();
                     bundle.putLong("trackselected",selectedItem.getTrackid());
                    intent.putExtras(bundle);                   
                   //Envoi du resultat à l'origine
                    setResult(RESULT_OK, intent);
                    finish();


            }

        });

I get this error :

 FATAL EXCEPTION: main
 java.lang.ClassCastException: java.lang.Integer
    at com.milesbox.sport.tracker.ListTracksActivity$1.onItemClick(ListTracksActivity.java:44)
    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
    at android.widget.ListView.performItemClick(ListView.java:3746)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1980)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3691)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
    at dalvik.system.NativeStart.main(Native Method)

Answers


Thank you FD_, when i say it was too big to see what is wrong, this is my method(getItem) that return an item that was wrong (copy paste too quick).


Need Your Help

ASP.NET MVC - Display Result of Serverside Process

asp.net asp.net-mvc

I'm very new to MVC, and just building my first site, using NerdDinner as an example. I'm wondering what is the best approach to displaying the result of a server-side process. eg on a screen where a