【问题标题】:SherlockFragment Pull to RefreshSherlockFragment 拉取刷新
【发布时间】:2014-02-10 00:52:35
【问题描述】:

您好,如何使用 Actionbar sherlock 片段和 ViewSwitcher 实现 chrisbanes Pull to Refresh Library

我正在使用此代码

Main.java

    // get an instance of FragmentTransaction from your Activity
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    //add fragment to LinearLayout(fragment_layout)
    TemplateListActivity myFragment = new TemplateListActivity();
    fragmentTransaction.add(R.id.fragment_layout, myFragment);
    fragmentTransaction.commit();

SherlockFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_template_list,
            container, false);

    vsSwitcher = (ViewSwitcher) view.findViewById(R.id.vsSwitcher);
    lvNameList = (ListView) view.findViewById(R.id.lvNameList);
    btnViewSwitcher = (Button) view.findViewById(R.id.button1);
    btnViewSwitcher.setOnClickListener(this);
    getList();


    mPullToRefresh = (PullToRefreshLayout) view.findViewById(R.id.ptr_layout);

    ActionBarPullToRefresh
            .from(getSherlockActivity())
            .allChildrenArePullable()
            .listener(this)
            .setup(mPullToRefresh);
    return view;
}

SherlockFragment.xml

相对布局

   >Linear layout
     >Button1
     >Button2
     >Button3


>uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout
     >ViewSwitcher
        >Linear Layout
           >ListView
        >Linear Layout
           >Toggle Button

所以当我运行代码时,pull to refresh 不起作用,其他布局也不起作用。我希望你们能帮助我。

【问题讨论】:

    标签: android-listview actionbarsherlock pull-to-refresh viewswitcher


    【解决方案1】:

    好的,我通过将 Viewgroup 指向特定布局得到答案

        View view = inflater.inflate(R.layout.fragment_template_list,
                container, false);
        ViewGroup viewGroup = (ViewGroup) view.findViewById(R.id.ptr_layout);
    

    并插入拉动以刷新到该视图组

        mPullToRefresh = new PullToRefreshLayout(viewGroup.getContext());
    
        ActionBarPullToRefresh
                .from(getSherlockActivity())
                .insertLayoutInto(viewGroup)
                .theseChildrenArePullable(view.findViewById(R.id.lvNameList))
                .listener(this)
                .setup(mPullToRefresh);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-14
      • 2019-04-15
      相关资源
      最近更新 更多