Tôi đang sử dụng bộ điều hợp máy nhắn tin phân đoạn để khởi tạo lớp phân đoạn của mình. Tôi có thể làm như vậy nhưng vấn đề của tôi là phương thức getItem() của tôi được gọi hai lần là tạo ra vấn đề hơn nữa.can u giải thích cho tôi lý do tại sao nó đang xảy ra.phương thức getItem() được gọi hai lần khi sử dụng Bộ chuyển đổi phân trang Fragment
package com.creatiosoft.rssfeed.adaptor;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;
import com.creatiosoft.rssfeed.utils.RssItem;
import com.viewpagerindicator.IconPagerAdapter;
public class NewsFeedsAdapter extends FragmentPagerAdapter implements
IconPagerAdapter {
int[] icon = null;
String[] content = null;
String[] URLs = null;
Context cont;
public NewsFeedsAdapter(FragmentManager fm, Context context) {
super(fm);
Log.i("jk", "constructor");
this.cont = context;
RssItem newsFeedAppliaction = (RssItem) cont;
/*
* Retrieving the values of the Icons and contents from the application
* class in utils package
*/
icon = newsFeedAppliaction.getICONS();
content = newsFeedAppliaction.getCONTENT();
URLs = newsFeedAppliaction.getURL();
}
/** instantiate a new fragment class */
@Override
public Fragment getItem(int position) {
Log.i("yt", "hello" + position);
return TestFragment.newInstance(position % content.length, cont);
}
@Override
public CharSequence getPageTitle(int position) {
return content[position % content.length].toUpperCase();
}
public int getIconResId(int index) {
return icon[index];
}
/** return the no of views on the basis of array items */
@Override
public int getCount() {
Log.i("hi", "length" + content.length);
return content.length;
}
}
tôi kêu gọi Adapter với mã này:
NewsFeedsAdapter adapter = new NewsFeedsAdapter(
getSupportFragmentManager(), getApplicationContext());
/**
* get the id of the view pager declared in the xml resource and set the
* adaptor on the view pager
*/
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
//pager.setCurrentItem(0);
/**
* Tab page indicator class is used to indicate the tabs and is accessed
* from the library class
*/
TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
indicator.setViewPager(pager);
vui lòng cung cấp cho tôi mã mẫu nếu có thể. – yokees
@ Rishabh.CreatioSoft Có bạn đi. :) – AedonEtLIRA
nhưng cho tôi biết một vị trí điều trả về cho tôi 0 & 1 cả trong getItem khi PagerAdapterCall.Vì vậy, chúng tôi đang nhận được đối tượng mảnh trên 1 vị trí. Làm thế nào bạn có thể nói mã của bạn chúng tôi chính xác. – yokees