简体   繁体   English

setAdapter“调用需要API级别11(当前最小值为8):android.widget.AbsListView #setAdapter”?

[英]setAdapter “Call requires API level 11 (current min is 8): android.widget.AbsListView#setAdapter”?

I'm calling the setAdapter() method in a class that extends Fragment . 我在扩展Fragment的类中调用setAdapter()方法。 Note that I have imported android.support.v4.app.Fragment . 请注意,我已导入android.support.v4.app.Fragment

However I get an error stating that the API level is required to be level 11. 但是我收到一个错误,指出API级别必须是11级。

What do I have to do so that I can fix this without changing minSdkVersion="8" to minSdkVersion="11" 我该怎么办才能解决这个问题,而不minSdkVersion="8"更改为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. 注意:我尝试将targetSdkVersion减少到10.但是我得到了错误。 Please help! 请帮忙!

Edit : I don't understand why it's termed as AbsListVew when all that I have used is a ListView . 编辑:当我使用的所有内容都是ListView时,我不明白为什么它被称为AbsListVew Also, note that I've used a custom adapter. 另外,请注意我使用了自定义适配器。

EventListAdapter extends ArrayAdaptere<ListContent> and shows NO ERROR. EventListAdapter扩展了ArrayAdaptere<ListContent>并显示NO ERROR。

For your reference here is the xml layout code snippet for R.id.ListView1 这里是R.id.ListView1的xml布局代码片段供您参考

<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

“运行Android Lint”会使一些标记和标记导致此错误。

Solution is just casting type to correct subtype as later Android versions introduced method call with same name. 解决方案只是转换类型以更正子类型,因为后来Android版本引入了具有相同名称的方法调用。

@SuppressWarnings({ "unchecked", "rawtypes" })

EventListAdapter adapter = new EventListAdapter(activity, R.layout.eventlist_row, item);
lv = (ListView) getView().findViewById(R.id.listView1);
((AdapterView)lv).setAdapter(adapter); //ERROR SOLVED HERE

正如你可以在文档中看到setAdapter()的方法AbsListView可刚刚从API级别11.因此,有没有什么可以做,你可以只投最终你AbsListViewListViewGridView ,然后调用setAdapter()

I solved the "abstract method not implemented error" by casting my setAdapter method like this: 我通过像这样强制转换setAdapter方法解决了“抽象方法未实现错误”:

 @SuppressWarnings("unchecked")
 public void setAdapterSDK8(Adapter adapter) {
    ((AdapterView) this).setAdapter(adapter);
    ((StaggeredGridView) this).setAdapter((ListAdapter) adapter);
 }

This is related to the etsy staggered gridview 这与etsy交错的gridview有关

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用需要API级别11(当前最小值为8):android.widget.EditText#setAlpha - Call requires API level 11 (current min is 8): android.widget.EditText#setAlpha 调用需要API级别11(当前最小值为1) - Call requires API level 11 (current min is 1) 呼叫需要API级别14(当前最小值为11) - Call requires API level 14 (current min is 11) 调用需要API级别16(当前最小值为10):android.widget.ImageView#getMaxWidth - Call requires API level 16 (current min is 10): android.widget.ImageView#getMaxWidth 调用需要 API 级别 29(当前最小值为 21):`android.widget.NumberPicker#setTextColor` - Call requires API level 29 (current min is 21): `android.widget.NumberPicker#setTextColor` 调用需要API级别11(当前最小值为9)android.app.Activity#onCreateView - Call requires API level 11(current min is 9) android.app.Activity#onCreateView 调用需要API级别11(当前最小值为8):new android.app.AlertDialog.Builder - Call requires API level 11 (current min is 8): new android.app.AlertDialog.Builder android:editTextBackground需要API级别11(当前最小值为7) - android:editTextBackground requires API level 11 (current min is 7) ?android:attr / selectableItemBackground`需要API级别11(当前最小值为10) - ?android:attr/selectableItemBackground` requires API level 11 (current min is 10) 调用需要API级别11(当前最小值为8)android.app.Activity#onCreateView - Call requires API level 11(current min is 8) android.app.Activity#onCreateView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM