How rise method from purpose fragment #3
Radzhab opened this issue · 1 comments
Radzhab commented
I want from MainActivity get CheeseListFragment method GetRequest. I create 10 instance of CheeseListFragment.
MainActivity.java
private void setupViewPager(ViewPager viewPager, String[] items) {
adapter = new Adapter(getSupportFragmentManager());
for (int i=0; i<items.length; i++){
adapter.addFragment(new CheeseListFragment(), items[i]);
}
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
if (adapter!=null) {
List<Fragment> list = new ArrayList<Fragment>();
list = adapter.mFragments; // Get Curren
list[i].GetRequest; // I want make it
}
}
}
CheeseListFragment.java
public class CheeseListFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
.....
return rv;
}
public void GetRequest(int page){
/// http get request
}
}
Suleiman19 commented
You can use an interface if you want to access a method from your Activity in your Fragment.
http://developer.android.com/training/basics/fragments/communicating.html
Moreover, please post relevant questions either on the blog comments where I'll be happy to help, or in Chris's sample. The issues section is intended for issues pertaining to this repository only.
Thanks.