Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:32:33+00:00 2026-06-14T15:32:33+00:00

I’ve managed to put together a custom BaseAdapter. This adapter is used to display

  • 0

I’ve managed to put together a custom BaseAdapter. This adapter is used to display three TextViews per list item. Works absolutely perfectly when there is one ListView within the activity.

However, I’m using a fragmented activity with 3 fragments – 2 of which contain a ListView which needs to use my custom adapter and XML.

When it comes to loading these two ListViews, firing the onItemClickListener on the first ListView loaded causes the following error:

11-20 18:02:15.295: E/AndroidRuntime(18563): java.lang.IllegalStateException: 
The content of the adapter has changed but ListView did not receive a 
notification. Make sure the content of your adapter is not modified from 
a background thread, but only from the UI thread. [in ListView(2131165192, 
class android.widget.ListView) with 
Adapter(class com.my.project.Adapter_CustomList)]

I don’t want the adapter to have changed – each ListView adapter is using a new Adapter_CustomList() so I’m not sure as to why they’re being referenced as the same adapter?

The adapter takes getActivity() as the context – since this is the same for both, is this causing the problem? Is there any way round this, or is this yet another drawback for fragments?

Custom Adapter is roughly as follows, I’ve taken some arbitrary chunks of code out…

public class Adapter_CustomList extends BaseAdapter {

private static ArrayList<Custom> results;

private LayoutInflater mInflater;

public Adapter_CustomList(Context context, ArrayList<Custom> res) {
    results = res;
    mInflater = LayoutInflater.from(context);
}

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

public Object getItem(int position) {
    return results.get(position);
}

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

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.custom_row_view, null);
        holder = new ViewHolder();

        //Set ViewHolder vars from inflated view

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    //Sets the TextViews

    return convertView;
}

static class ViewHolder {
    //Contains the TextView text vars
}
}

The activity is using a FragmentPagerAdapter (as generated by Eclipse):

public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int i) {
        Fragment fragment;
        switch (i){
            case 1: 
                fragment = new Frag_ListOne();
                break;
            case 2:
                fragment = new Frag_ListTwo();
                break;
            default:
                fragment = new Frag_Temporary();
                break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0: return getString(R.string.main_fragment1).toUpperCase();
            case 1: return getString(R.string.main_fragment2).toUpperCase();
            case 2: return getString(R.string.main_fragment3).toUpperCase();
        }
        return null;
    }
}

Fragment example, both are almost identical but with unique layout files.

public class Frag_ListOne extends Fragment {

private ListView ListView;
private Adapter_CustomList listAdapter;

private Fetcher fetcher;

public Frag_ListOne(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    return inflater.inflate(R.layout.frag_list_one, container, false);
}

@Override
public void onStart(){
    super.onStart();
    ListView = (ListView) getActivity().findViewById(R.id.frag_one_list);
    ListView.setEmptyView(getActivity().findViewById(R.id.frag_one_list_spinner));
    if (listAdapter != null){
        setListAdapter();
    } else {
        //This will always be called for now....
        sendRequest();
    }
}

private void sendRequest(){
    fetcher = new Fetcher();
    fetcher.execute("http://myapiurl.com");
}

private void cancelFetch(){
    if (fetcher != null && 
            (fetcher.getStatus() == AsyncTask.Status.PENDING || fetcher.getStatus() == AsyncTask.Status.RUNNING)){
        fetcher.cancel(true);
    }
}

private void displayError(String errMsg){
    //Log errMsg
}

private void createListAdapter(ArrayList<Result> res){
    listAdapter = new Adapter_CustomList(getActivity(), res);
    setListAdapter();
}

private void setListAdapter(){
    ListView.setAdapter(listAdapter);
    ListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            Result r = (Result) ListView.getItemAtPosition(position);
            Intent intent = new Intent(getActivity(), ViewResultActivity.class);
            intent.putExtra(F_List.INTENT_VIEW_RESULT_OBJ, r);
            startActivity(intent);
        }
    });
}

//Extended AsyncTask, essentially
public class Fetcher extends JSONRequest{

    @Override
    protected void onSuccess(JSONObject req, JSONObject res){
        if (req != null && res != null){
            try{
                JSONArray jsons = res.getJSONArray("results");
                ArrayList<Result> res = new ArrayList<Result>();
                if (jsons.length() > 0){
                    for (int i=0;i<jsons.length();i++){
                        JSONObject jo = jsons.getJSONObject(i);
                        r = new Result();
                        r.setLineOne(jo.getInt("line1"));
                        r.setLineTwo(jo.getString("line2"));
                        r.setLineThree(jo.getString("line3"));
                        res.add(r);
                    }
                    createListAdapter(res);
                } else {
                    //Nothing found
                }
            } catch (JSONException e){}
        } else {
            //Null received
        }
    }

    @Override
    protected void onError(String errMsg){}

    @Override
    protected void onCancel(){}

}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:32:34+00:00Added an answer on June 14, 2026 at 3:32 pm

    the adapter code looks ok – I’ve done something similar where I run two list views in separate fragments. (I’m making the assumption that results is actually equal to offerResults)

    Maybe there’s an issue with the way you’re attaching to the list views?

    • Make sure that the Adapter and listViews are all being referenced in the fragments not the activity.

    • Check to see if you set the adapter and then change the list which drives it without calling adapter.notifyDataSetChanged()

    Can be of more use with reference to the Fragments and the way the adapter is declared 🙂

    Edit:

    I was running a system where I would inflate 2 fragments into FrameLayouts using the FragmentManager instead of a FragmentPagerAdapter.

    I’d double check to see if the fragments are being created and accessed correctly in the fragment pager adapter. You can do this by logging the fragmentId from getItem()

    Also be careful with the way getItem(…) is written since that can lead to out of memory errors really quickly if you keep spawning new fragments. Instead I’d look at using the fragment manager and tags to manage the creation of new fragments.

    Another thought is to consider setting up your lists inside sliding drawers so that they can pull them out as needed.

    Edit 2:
    try the following changes – this way the list lives in the fragment’s memory and isn’t part of the AsyncTask which might be GCed upon completion.

     private ArrayList<Result> resultList = new ArrayList<Result>();
     private Adapter_CustomList adapter = null;
    
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
         View v = inflater.inflate(R.layout.frag_list_one, container, false);
         listView = (ListView) v.findViewById(R.id.frag_one_list);
         listView.setEmptyView(v.findViewById(R.id.frag_one_list_spinner));
         adapter = new Adapter_CustomList(getActivity(), resultList);
         listView.setAdapter(adapter);
     }
    
     @Override
     public void onStart(){
         super.onStart();
     }
    
     //Extended AsyncTask, essentially
     public class Fetcher extends JSONRequest{
    
    @Override
    protected void onSuccess(JSONObject req, JSONObject res){
        if (req != null && res != null){
            try{
                JSONArray jsons = res.getJSONArray("results");
                if (jsons.length() > 0){
                    for (int i=0;i<jsons.length();i++){
                        JSONObject jo = jsons.getJSONObject(i);
                        r = new Result();
                        r.setLineOne(jo.getInt("line1"));
                        r.setLineTwo(jo.getString("line2"));
                        r.setLineThree(jo.getString("line3"));
                        resultList.add(r);
                    }
                    adapter.notifyDataSetChanged();
                } else {
                    //Nothing found
                }
            } catch (JSONException e){}
        } else {
            //Null received
        }
    }
    
    @Override
    protected void onError(String errMsg){}
    
    @Override
    protected void onCancel(){}
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.