accessing Viewpager child elements for clicking and diplaying another view pager elements in a small window

前端 未结 1 1195
Happy的楠姐
Happy的楠姐 2021-01-27 05:33

I called the fragements as

           List fragments = new Vector();
            fragments.add(Fragment.instantiate(context, Frag         


        
1条回答
  •  生来不讨喜
    2021-01-27 06:09

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

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

    In this 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.

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

    0 讨论(0)
提交回复
热议问题