20

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" /> 
1
  • Make sure you're extending support fragment... just remove the import and change it Commented Sep 22, 2012 at 16:19

4 Answers 4

71

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

And I had to uncheck "When saving files, check for errors" under Preferences > Android > Lint Error Checking.
7

Solution is just casting type to correct subtype as later Android versions introduced method call with same name.

@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 

2 Comments

I don't see a crash, explain, your comment is not useful otherwise... You are casting to pre API 11 AdapterView so what you do here don't have anything with newer API , you are just telling compiler to use right method that exist in pre API 11 ...
sorry, I tested your solution and I had a "abstract method not implemented error". I have however found a workaround for my problem. in hindsight the solution might have work, it was my implementation that was not well executed. I will delete my response later since it was not relevent
0

As you can see in the docs setAdapter() method on AbsListView is available just from API Level 11. So there isn't much you can do, you can just cast eventually your AbsListView to a ListView or GridView and then call setAdapter().

3 Comments

I've used only a ListView in my code. Just that I customized my Adapter. Where is the error then?
@Ovidu : I've posted the code. Could you please check and tell me now? Thanks:)
Can you also post the xml snippet where R.id.listView1 is declared? Maybe it's declared as an AbsListView there?
0

I solved the "abstract method not implemented error" by casting my setAdapter method like this:

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

This is related to the etsy staggered gridview

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.