本文介绍了setAdapter"调用需要API级别11(目前最小为8):android.widget.AbsListView#setAdapter"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话在扩展片段 A类 setAdapter()方法。请注意,我已导入 android.support.v4.app.Fragment

不过,我得到一个错误,指出API等级要求是11级

什么我必须做的,这样我可以解决这个问题,而不改变的minSdkVersion =8的minSdkVersion =11

 包foo.bar.qux;

进口的java.util.Calendar;
进口java.util.Date;

进口org.w3c.dom.Document中;
进口org.w3c.dom.NodeList;

进口android.support.v4.app.Fragment;

进口android.app.Activity;
进口android.os.Bundle;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.LinearLayout;
进口android.widget.ListView;
进口android.widget.TextView;

公共类TabFragmentList扩展片段{

    串类,XML;
    节点列表节点;
    INT numResults;
    私人的ListView LV;
    日期日期;

    @覆盖
    公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
            捆绑savedInstanceState){
        如果(集装箱== NULL)返回NULL;
        返程(的LinearLayout)inflater.inflate(R.layout.eventlist,集装箱,
                假);
    }

    @覆盖
    公共无效onActivityCreated(包savedInstanceState){
        super.onActivityCreated(savedInstanceState);
        活性活性= getActivity();
        如果(活动!= NULL){
            最后的日历C = Calendar.getInstance();
            的listContent []项目=新的listContent [3];
            类别=(字符串)activity.getIntent()。getExtras()
                    获得(类);
            。XML =(字符串)activity.getIntent()getExtras()获得(XML)。
            TextView的电视=(TextView中)getView()findViewById(R.id.category)。
            tv.setText(类);
            节点= doc.getElementsByTagName(事件);
            的for(int i = 0;我3;;我++){
                c.add(Calendar.DATE,1);
                日期= c.getTime();
                项目[i] =新的listContent();
                项目[I] .setList(节点,类别,日期);
            }
            EventListAdapter适配器=新EventListAdapter(活动,
                    R.layout.eventlist_row,项目);
            吕=(ListView控件)getView()findViewById(R.id.listView1);
            lv.setAdapter(适配器); //错误这里显示
        }
    }
}
 

注:我试过减少targetSdkVersion至10。然而,我得到的错误。请帮帮忙!

编辑:我不明白为什么它称为 AbsListVew 的时候,我都用了一个的ListView 。另外请注意,我用一个自定义的适配器。

EventListAdapter 扩展 ArrayAdaptere<的listContent> 键,显示NO ERROR

为您的网站引用是XML布局code段为R.id.ListView1

 <的ListView
        机器人:layout_margin =10dp
        机器人:dividerHeight =10.0sp
        机器人:ID =@ + ID / ListView1的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT/>
 

解决方案

右键单击该项目文件夹> Android的工具>清除链接标记

运行Android林特使得一些标记和标记导致此错误。

I'm calling the setAdapter() method in a class that extends Fragment. Note that I have imported android.support.v4.app.Fragment .

However I get an error stating that the API level is required to be level 11.

What do I have to do so that I can fix this without changing minSdkVersion="8" to minSdkVersion="11"

package foo.bar.qux;

import java.util.Calendar;
import java.util.Date;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import android.support.v4.app.Fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class TabFragmentList extends Fragment {

    String category, xml;
    NodeList nodes;
    int numResults;
    private ListView lv;
    Date date;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (container == null) return null;
        return (LinearLayout) inflater.inflate(R.layout.eventlist, container,
                false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Activity activity = getActivity();
        if (activity != null) {
            final Calendar c = Calendar.getInstance();
            ListContent[] item = new ListContent[3];
            category = (String) activity.getIntent().getExtras()
                    .get("category");
            xml = (String) activity.getIntent().getExtras().get("xml");
            TextView tv = (TextView) getView().findViewById(R.id.category);
            tv.setText(category);
            nodes = doc.getElementsByTagName("event");
            for (int i = 0; i < 3; i++) {
                c.add(Calendar.DATE, 1);
                date = c.getTime();
                item[i] = new ListContent();
                item[i].setList(nodes, category, date);
            }
            EventListAdapter adapter = new EventListAdapter(activity,
                    R.layout.eventlist_row, item);
            lv = (ListView) getView().findViewById(R.id.listView1);
            lv.setAdapter(adapter); // ERROR SHOWN HERE
        }
    }
}

Note : I tried reducing the targetSdkVersion to 10. Yet I get the error. Please help!

Edit : I don't understand why it's termed as AbsListVew when all that I have used is a ListView. Also, note that I've used a custom adapter.

EventListAdapter extends ArrayAdaptere<ListContent> and shows NO ERROR.

For your reference here is the xml layout code snippet for R.id.ListView1

<ListView
        android:layout_margin="10dp"
        android:dividerHeight="10.0sp"
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
解决方案

Right click on the project folder > Android tools > Clear Link Markers

"Run Android Lint" makes some markers and the markers cause this error.

这篇关于setAdapter&QUOT;调用需要API级别11(目前最小为8):android.widget.AbsListView#setAdapter&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 02:04