我叫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.