Question

Hi how can I implement chrisbanes Pull to Refresh Library using Actionbar sherlock fragment and ViewSwitcher?

I'm using this code

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

Relative Layout

   >Linear layout
     >Button1
     >Button2
     >Button3


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

So when I run the code pull to refresh is not working and the other layouts are not working too. I hope you can help me guys.

Was it helpful?

Solution

Ok I got the anwer by pointing the Viewgroup to a specific layout

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

and insert pull to refresh to that viewgroup

    mPullToRefresh = new PullToRefreshLayout(viewGroup.getContext());

    ActionBarPullToRefresh
            .from(getSherlockActivity())
            .insertLayoutInto(viewGroup)
            .theseChildrenArePullable(view.findViewById(R.id.lvNameList))
            .listener(this)
            .setup(mPullToRefresh);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top