如何在单击相同片段时调用片段本身

时间:2017-02-17 09:58:47

标签: android

我是初学者,我需要帮助,在点击不同的数据时调用片段本身

当我要点击片段本身时,URL没有再次点击, 我需要做什么?

public  void OnReceivablesSummeryOnClick(long tenantId,long userId)
    {
        Bundle bundle =new Bundle();

        bundle.putLong("TenantId",tenantId);
        bundle.putLong("SalesPersonId",userId);

        ReceivablesSummaryFragment fragment=new ReceivablesSummaryFragment();

        fragment.setFragmentActionListener(this);
        fragment.setArguments(bundle);

        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.home_container,fragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();    
    }

点击片段

if(mReceivableSummeryOnClickListener!= null) {
    SalesPersonWiseAgeingVO salesPersonWiseAgeingVO = mSalesPersonWiseAgeingVOsList.get(position);

    if (salesPersonWiseAgeingVO != null && !salesPersonWiseAgeingVO.getSalesPersonName().equalsIgnoreCase("Total")) {
                               mReceivableSummeryOnClickListener.OnReceivablesSummeryOnClick(mTenantId, userId);
     }
}

在ReceivableSummeryFragment 中 public void onAttach(Context context){ super.onAttach(上下文);

开关(总和){

case 1:

    if (context instanceof OnReceivablesSummarySelectionListener) {

        mReceivablesSummarySelectionListener = (OnReceivablesSummarySelectionListener) context;

    }

    break;
case 2:

    if (context instanceof OnReceivablesSummeryOnClickListener) {

        mReceivableSummeryOnClickListener = (OnReceivablesSummeryOnClickListener) context;

    }

    break;

default:

    throw new RuntimeException(context.toString()

            + " must implement OnReceivablesSummarySelectedListener");

} }

Onclick of Fragment 覆盖

public void onClick(View v){     int num = 2;

switch (num) { //for hierarchy.

    case 1:

        if (mReceivablesSummarySelectionListener != null) {

            SalesPersonWiseAgeingVO salesPersonWiseAgeingVO = mSalesPersonWiseAgeingVOsList.get(position);

            if (salesPersonWiseAgeingVO != null && !salesPersonWiseAgeingVO.getSalesPersonName().equalsIgnoreCase("Total")) {

                mReceivablesSummarySelectionListener.OnReceivablesSummarySelected(mTenantId, salesPersonWiseAgeingVO.getSalesPersonId(),                                                     salesPersonWiseAgeingVO.getSalesPersonName());
            }
        }
        break;
    case 2:

        if (mReceivableSummeryOnClickListener != null) {

            SalesPersonWiseAgeingVO salesPersonWiseAgeingVO = mSalesPersonWiseAgeingVOsList.get(position);

            if (salesPersonWiseAgeingVO != null && !salesPersonWiseAgeingVO.getSalesPersonName().equalsIgnoreCase("Total")) {

                mReceivableSummeryOnClickListener.OnReceivablesSummeryOnClick(mTenantId, userId);           
            }

        }

    break;

接口: -

public interface OnReceivablesSummeryOnClickListener {

void OnReceivablesSummeryOnClick(long tenantId, long userId);

}

1 个答案:

答案 0 :(得分:0)

在这里你去..你可以从它自己调用相同的片段:

    .lower {
      border-width: 50px;
      border-color: black red green blue;
      border-style: solid;
    }

    .upper {
      border-width: 50px 50px 0 50px;
      border-color: black transparent transparent transparent;
      border-style: solid;
      height: 50px;
    }
    .disp {
      display: inline-flex;
    }
    <div class="triangles disp">
       <span class="lower"></span>
       <span class="upper"></span>
       <span class="lower"></span>
    </div>

将片段中的数据作为:

ReceivablesSummaryFragment innerFragment = new ReceivablesSummaryFragment ().newInstance("pass your data1", "pass your data2");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        innerFragment .setEnterTransition(new Slide(Gravity.RIGHT));
        innerFragment .setExitTransition(new Slide(Gravity.LEFT));
    }

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.layoutContainer, innerFragment , title);// you can provide different title as you click on inner fragments
    fragmentTransaction.addToBackStack(title);
    fragmentTransaction.commit();

它在我的应用程序中完美运行..希望它有所帮助..快乐编码......