0

嗨我怎么能实施chrisbanes Pull to Refresh Library使用Actionbar sherlock片段和ViewSwitcher?SherlockFragment拉到刷新

我使用这个代码

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 

所以,当我运行代码拉刷新不工作和其他布局不工作了。我希望你能帮助我。

回答

1

好吧,我通过指向ViewGroup中的具体布局

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

得到了前面回答并插入拉刷新到ViewGroup中

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

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