How to get the position of an item that is focused in a listview by
scrolling up or down using the up/down keys?

Also, what is the difference between onClick and onItemSelected? i.e.
when is each one called??

Thanks.


On Dec 27, 3:03 pm, Romain Guy <[email protected]> wrote:
> In short: you don't, you can't, you won't :)
>
> Explanations 
> here:http://android-developers.blogspot.com/2008/12/touch-mode.html
>
>
>
> On Fri, Dec 26, 2008 at 3:26 PM, Timothy DeWees <[email protected]> wrote:
>
> > Hello,
>
> > I've seen a few post on this but have never seen or understood the
> > solution.  I have an application that is showing a list of items from
> > a database.  I extended the CursorAdapter and added an icon in front
> > of the item to easily show type.
>
> > When I navigate the items using the track-pad, it shows the selected
> > item; however, when I click the item, the selection goes away.  It's
> > still there and when I use the track-pad again, it seems to be getting
> > the focus back and then I can scroll.
>
> > What I want to happen is for the list item to appear highlighted when
> > I click it just like when I navigate to it with the trackpad.
>
> > Any suggestions?
>
> > Here are my onClick and onItemSelected:
>
> >   �...@override
> >    protected void onListItemClick(ListView l, View v, int position,
> > long id) {
> >        super.onListItemClick(l, v, position, id);
> >        setSelection(position);
> >        movieId = id;
> >    }
> >   �...@override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.main);
>
> >        mDbHelper = new MoviesDbAdapter(this);
> >        mDbHelper.open();
> >        Button filterButton = (Button)findViewById
> > (R.id.filter_button);
> >        filterButton.setOnClickListener( new View.OnClickListener() {
> >                public void onClick(View v){
> >                        EditText filter = 
> > (EditText)findViewById(R.id.filter_text);
> >                        filterExpr = filter.getText().toString();
> >                        fillData();
> >                }
> >        });
> >        getListView().setAddStatesFromChildren(false);
> >        getListView().setItemsCanFocus(true);
> >        getListView().setOnItemSelectedListener( new
> > OnItemSelectedListener() {
> >                public void onItemSelected(AdapterView<?> parent, View v, int
> > possition, long id) {
> >                        v.setSelected(true);
> >                        movieId = id;
> >                }
> >                public void onNothingSelected(AdapterView<?> parent) {
> >                        parent.setSelection(-1);
> >                }
> >        });
> >        fillData();
> >    }
>
> --
> Romain Guy
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time
> to provide private support.  All such questions should be posted on
> public forums, where I and others can see and answer them

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to