在正确的位置显示片段单击内部的recyclerview

时间:2016-06-20 13:46:08

标签: android fragment android-recyclerview

问题 当我在点击事件的回收者视图中添加一个片段时,会显示片段,但它没有显示在回收器视图中的正确位置,原因是我无法放置适配器的正确位置(我使用getLayoutPosition方法)在FragmentTransaction.add()方法中。

  

recyclerViewAdapter.java

public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView adapterPositionText , layoutPositionText , bindviewPositionText;
        private FrameLayout childFragmentContainer;
        private Button showFragmentButton;

        public MyViewHolder(View itemView) {
            super(itemView);

            adapterPositionText = (TextView) itemView.findViewById(R.id.item_adapter_position);
            layoutPositionText =(TextView) itemView.findViewById(R.id.item_layout_position);
            childFragmentContainer = (FrameLayout) itemView.findViewById(R.id.child_fragment_container);
            childFragmentContainer.setVisibility(View.GONE);
            showFragmentButton = (Button) itemView.findViewById(R.id.show_fragment_button);
            bindviewPositionText = (TextView) itemView.findViewById(R.id.binviewHolder_position);
            showFragmentButton.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if(v == showFragmentButton){
                mRecyclerViewItemListener.addFragment( childFragmentContainer ,this.getAdapterPosition());
                Log.d("layout_position : " , ""+getLayoutPosition());
                if(childFragmentContainer.getVisibility() == View.GONE){
                    childFragmentContainer.setVisibility(View.VISIBLE);
                }
            }
        }
    }
  

ParentFragment.java

@Override
    public void addFragment(View view, int position) {
        mFragmentData =  mAdapterDataSet.get(position);
        mFragmentManager = getChildFragmentManager();
        mFragmentTransaction = mFragmentManager.beginTransaction();
        mChildFragment = new ChildFragment();
        mChildFragment.setChildFragData(mFragmentData);
        mFragmentTransaction.add(R.id.child_fragment_container ,mChildFragment, "chaild_fragment");
        mFragmentTransaction.commit();

    }
  

添加时如何放置viewholder(片段容器)的位置   片段容器中的片段

0 个答案:

没有答案