Sunday, 15 July 2012

onclicklistener - android wear gridviewpager onClick Listener -



onclicklistener - android wear gridviewpager onClick Listener -

i'm developing simple application in youb have different spots placed on google map. when click on spot details displayed in gridviewpager. application based on gridviewpager sample available sdk.

here layout spot details (nothing fancy)

<android.support.wearable.view.gridviewpager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:keepscreenon="true"/>

my problem i'm not able observe click event on card. i've tried doesn't work.

public class detailsactivity extends activity implements gridviewpager.onclicklistener { @override public void onclick(view v) { }

i've tried view.onclicklistener.

have thought ?

there 2 issues here. first, if want create gridviewpager clickable, need tell hear click events - implementing onclicklistener interface isn't sufficient. need this:

public class detailsactivity ... { @override public void oncreate(bundle savedinstancestate) { ... gridviewpager pager = (gridviewpager)findviewbyid(r.id.pager); pager.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // set onclick logic here } }); ... } }

that beingness said, however, based on description sounds want set click handlers on individual pages within grid, not on entire grid. if so, you'll need similar in each page's fragment class. example:

public class mypagefragment extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view result = inflater.inflate(...); result.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // set onclick logic here } }); ... homecoming result; } }

note: if using cardfragments in gridviewpager, set onclicklistener in oncreatecontentview override. otherwise, above fragment-based illustration should apply.

android onclicklistener android-wear

No comments:

Post a Comment