当前位置: 首页 > 知识库问答 >
问题:

怎么解决这个??>>与FragmentStatePagerAdapter不兼容

印劲
2023-03-14

我有一个程序使用片段,但我有一个问题,当我包括列表视图在我的传呼机当一个项目在滑动菜单选择。

这些错误是:

在制表符适配器上

公共类TabsPagerAdapter扩展FragmentStatePagerAdapter{

public TabsPagerAdapter(android.support.v4.app.FragmentManager fragmentManager) {
    super(fragmentManager);
}

@Override
public FragmentActivity getItem(int index) {

    switch (index) {
    case 0:
        return new SoloAttractionFragment();
    case 1:
        return new KaranganyarAttractionFragment();
    case 2:
        return new SukoharjoAttractionFragment();
    }

    return null;
}

@Override
public int getCount() {
    // get item count - equal to number of tabs
    return 3;
}

}

行中的错误:

public FragmentActivity getItem(int index){

此行有多个标记-实现android.support.v4.app.FragmentStatePagerAdapter.GetItem-返回类型与FragmentStatePagerAdapter.GetItem(int)不兼容-返回类型与FragmentStatePagerAdapter.GetItem(int)不兼容

请帮帮我,谢谢

另一个类相关:

公共类SoloAttractionFragment扩展FragmentActivity{

// All static variables
static final String URL = "http://api.androidhive.info/music/music.xml";
// XML node keys
public static final String KEY_SONG = "song"; // parent node
public static final String KEY_ID = "id";
public static final String KEY_TITLE = "title";
public static final String KEY_ARTIST = "artist";
public static final String KEY_DURATION = "duration";
public static final String KEY_THUMB_URL = "thumb_url";

ListView list;
LazyAdapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_attraction_solo);

    ArrayList<HashMap<String, String>> songsList = new 
            ArrayList<HashMap<String, String>>();

    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(URL); // getting XML from URL
    Document doc = parser.getDomElement(xml); // getting DOM element

    NodeList nl = doc.getElementsByTagName(KEY_SONG);
    // looping through all song nodes &lt;song&gt;
    for (int i = 0; i < nl.getLength(); i++) {
        // creating new HashMap
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) nl.item(i);
        // adding each child node to HashMap key =&gt; value
        map.put(KEY_ID, parser.getValue(e, KEY_ID));
        map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
        map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
        map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
        map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));

        // adding HashList to ArrayList
        songsList.add(map);
    }

    list=(ListView)findViewById(R.id.list);

    // Getting adapter by passing xml data ArrayList
    adapter=new LazyAdapter(this, songsList);
    list.setAdapter(adapter);

    // Click event for single list row
    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // TODO Auto-generated method stub
        }
        });
}

这是列表视图的适配器:

公共类LazyAdapter扩展了BaseAdapter{

private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());
}

public int getCount() {
    return data.size();
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_row, null);

    TextView title = (TextView)vi.findViewById(R.id.title); // title
    TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
    TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

    HashMap<String, String> song = new HashMap<String, String>();
    song = data.get(position);

    // Setting all values in listview
    title.setText(song.get(SoloAttractionFragment.KEY_TITLE));
    artist.setText(song.get(SoloAttractionFragment.KEY_ARTIST));
    duration.setText(song.get(SoloAttractionFragment.KEY_DURATION));
    imageLoader.DisplayImage(song.get(SoloAttractionFragment.KEY_THUMB_URL), position, thumb_image);
    return vi;
}

}

共有2个答案

宦兴朝
2023-03-14
public class SoloAttractionFragment extends android.support.v4.app.Fragment
云新知
2023-03-14

您不能从getItem()返回FragmentActivity,因为FragmentActivity不是片段,而是可以包含片段的activity。getItem()必须返回片段或列表片段。

 类似资料:
  • 失败:生成失败,出现异常。 > 其中:Script“C:\flutter\packages\flutter_tools\gradle\flutter.gradle”行:900 错误:任务“:app:CompileFlutterBuildDebug”执行失败。 进程“command”C:\flutter\bin\flutter.bat“已完成,退出值为非零%1 生成在%12s中失败异常:Gradle

  • 说我这个属性无效、不合法的,没有定义的 controller是有定义对象的,结果在controller就报上面的错了 InspectionPlan 对象有个属性是private List<FEntity> FEntity; FEntity对象属性FInspectionStandard的get/set方法也有,名字也取跟前端一样。但提交就报错了。请问这是怎么回事? js请求是这样的

  • 问题: impl: @Service public class GraduateCollegeServiceImpl extends ServiceImpl<GraduateCollegeMapper, GraduateCollege> implements IGraduateCollegeService { controller: @Api(tags="各高校") @RestController

  • 附注:我试着把hadoop作为一个单节点安装,但不起作用,所以我试着把它删除,把所有的东西都作为一个双节点设置来重做,所以我不得不重新格式化NameNode。我不知道这是否会影响到这一点。 编辑1:我修正了start-all.sh命令不工作,因为我修正了.bashrc中的错误。但是,当运行start-all.sh或start-dfs.sh等时,我会收到这些错误消息。 编辑2:修正了上面的错误,我更

  • 在线地址, https://stackblitz.com/edit/vue-c98wtb?file=src%2Fcomponents%... 先把数据往下滚动一下,然后再点击 Recovery 按钮, 视图没有更新

  • 这是我得到错误的相关代码。如果你需要看更多我的代码,让我知道,我会添加它。 我在互联网上寻找一个解决方案,也发现了类似的问题,但没有一个修复工作做任何事情来解决问题。如有任何帮助,我将不胜感激