android - Gallery captures trackball navigation -
the gallery traps trackball/dpad navigation horizontally.
here's example layout buttons on either side of gallery:
<linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android"> <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <gallery android:layout_height="match_parent" android:id="@+id/gallery" android:layout_width="match_parent" android:layout_weight="1" /> <button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout> when navigate gallery trackball can't escape buttons on either side. tried adding android:nextfocusleft="@id/button" gallery. tried adding first view in gallery's adapter.
is there way around this?
i figured out, bug in gallery. workaround extend gallery follows:
public class dpadablegallery extends gallery { public dpadablegallery(context context) { super(context); } public dpadablegallery(context context, attributeset attrs) { super(context, attrs); } @override public boolean onkeydown(int keycode, keyevent event) { switch (keycode) { case keyevent.keycode_dpad_left: if (getselecteditemposition()==0) { return false; } break; case keyevent.keycode_dpad_right: if (getselecteditemposition()==(getadapter().getcount()-1)) { return false; } } return super.onkeydown(keycode, event); } }
Comments
Post a Comment