Android的磨损gridviewpager的onClick监

Android的磨损gridviewpager的onClick监

本文介绍了Android的磨损gridviewpager的onClick监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的应用程序,其中youb有不同点放在谷歌地图。当我点击一个点,我得到了这显示在 GridViewPager 的详细信息。现在我的应用程序是基于的 GridViewPager 的样品可提供的SDK。

I'm developing a simple application in which youb have different spots placed on google map.When I click on a spot I get its details which are displayed in a GridViewPager.For now my application is based on the GridViewPager sample available with the sdk.

下面是我对现场的细节布置(没有任何幻想)

Here is my layout for the 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"/>

我现在的问题是,我不能够检测一个Click事件到卡上。我试过,但它不能正常工作。

My problem now is that I'm not able to detect a Click event on a card.I've tried this but it doesn't work.

public class DetailsActivity extends Activity implements GridViewPager.OnClickListener {


@Override
public void onClick(View v) {

}

我也试着View.OnClickListener。

I've also tried View.OnClickListener.

有什么想法?

推荐答案

有两个问题。首先,如果你真的想使GridViewPager点击,你需要告诉它监听点击事件 - 只是实现OnClickListener接口是不够的。所以,你需要做的是这样的:

There are two issues here. First, if you really want to make the GridViewPager clickable, you need to tell it to listen for click events - just implementing the OnClickListener interface isn't sufficient. So you need to do something like 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) {
                // put your onClick logic here
            }
        });

        ...
    }
}

话虽这么说,不过,根据您的描述,它听起来就像你真正想要的是建立个人网页上单击处理网格内,而不是在整个电网。如果是这样,那么你需要做的类似,但在每一个页面的片段类的东西。例如:

That being said, however, based on your description it sounds like what you actually want is to set up click handlers on individual pages within the grid, not on the entire grid. If so, then you'll need to do something similar but in each page's Fragment class. For 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) {
                // put your onClick logic here
            }
        });

        ...

        return result;
    }
}

请注意:如果您在您的GridViewPager使用CardFragments,那么你可能会设置OnClickListener在onCreateContentView覆盖。否则,上述片段为基础的例子应该适用。

Note: if you are using CardFragments in your GridViewPager, then you would probably set the OnClickListener in your onCreateContentView override. Otherwise, the above Fragment-based example should apply.

这篇关于Android的磨损gridviewpager的onClick监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:54