Sinigami
Sinigami

Reputation: 449

Focus in touch mode

I have the ListView with categories and gridview with items for selected category.

I need this: when I choose a category by clicking - set focus on first item in gridview. But now it works when I choose a category by keyboard...

Some code:

    gridView.requestFocus();
    gridView.setSelection(0);

Some Logs:

     gridView.isInTouchMode: true
     gridView.isFocusableInTouchMode: true

Thank you.

Upvotes: 0

Views: 3058

Answers (2)

Sinigami
Sinigami

Reputation: 449

I solved my issue with this code:

    gridView.requestFocusFromTouch();
    gridView.setSelection(0);

Upvotes: 1

SweetWisher ツ
SweetWisher ツ

Reputation: 7306

Try this code :

gridView.setFocusable(true); 
gridView.setFocusableInTouchMode(true);

And also set this attribute in your GriView

android:focusableInTouchMode="true"

Upvotes: 2

Related Questions