访问 Viewpager 子元素以在小窗口中单击和显示另一个视图寻呼机元素 [英] accessing Viewpager child elements for clicking and diplaying another view pager elements in a small window

查看:10
本文介绍了访问 Viewpager 子元素以在小窗口中单击和显示另一个视图寻呼机元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把这些片段称为

           List<Fragment> fragments = new Vector<Fragment>();
            fragments.add(Fragment.instantiate(context, Fragment1.class.getName()));
            fragments.add(Fragment.instantiate(context, Fragment2.class.getName()));
            mPageAdapter = new PageAdapter(activity.getSupportFragmentManager(),fragments);
            ViewPager pager = (ViewPager)findViewById(R.id.viewpager);
            pager.setAdapter(mPageAdapter);`

,但现在在片段类中,当尝试访问子按钮时

,but now in fragment class ,when trying to access the child button as

View v = inflater.inflate(R.layout.fragment1, container, false);

        btn = (ImageButton) v.findViewById(R.id.btn);
        btn.setOnTouchListener(new OnTouchListener() {}

,但是按钮没有产生点击事件,无法理解问题.其次,如何在当前窗口上方打开一个带有 viewpager 和片段的小窗口,以便用户触摸后窗口前面的窗口关闭,当前窗口可见时,单击片段按钮之一,用户可以滑动其元素,作为这里新使用viewpager,请指导

,but the button is not generating click event,not able to understand the problem. Secondly, how can I open a small window with viewpager and fragments ,above the present window,so user touches the back window front one goes off,and when front window is visible,onclick of one of fragment button ,user can swipe its elements,as here new in use of viewpager,kindly guide

推荐答案

你好像还没有完全理解inflater.inflate的意思,和你上一个问题一样.

It looks like you are not completely understand the meaning of inflater.inflate, it was the same problem in your previous question.

当调用 inflater.inflate 时,它会从您提供的 xml 中创建 new 视图对象.

When calling inflater.inflate it creat new View object from the xml you give it.

在这段代码中:

View v = inflater.inflate(R.layout.fragment1, container, false);
btn = (ImageButton) v.findViewById(R.id.btn);
btn.setOnTouchListener(new OnTouchListener() {}

您创建了新的视图对象,然后找到了它的按钮并向其添加了一个触摸侦听器事件.除非您要将此视图添加到片段中,否则该事件将永远不会触发.

You created new view object, than you found it's button and add a touch listener event to it. Unless you are going to add this view to the fragment, the event will never fire.

我认为您的意思是在片段类中使用 findViewById() 查找视图.

I think what you meant to do is finding your view using findViewById() inside your fragment class.

这篇关于访问 Viewpager 子元素以在小窗口中单击和显示另一个视图寻呼机元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆