访问Viewpager子元素的点击和diplaying另一种观点认为寻呼机元素在一个小窗口 [英] accessing Viewpager child elements for clicking and diplaying another view pager elements in a small window

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

问题描述

我叫fragements为

I called the fragements as

           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和片段,在present窗口上方,因此用户触摸后窗前面一条熄灭,当前窗是可见的,的onclick片段按钮中的一个,用户可以刷卡它的元素,因为这里新的使用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 的意思,这是同样的问题在previous的问题。

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。

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

在此code:

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子元素的点击和diplaying另一种观点认为寻呼机元素在一个小窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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