Search code examples
javaandroidlistadaptersimpleadapterjson

how to display multiple list objects using simplelist adapter in android


this is not working i would like to append the second SimpleAdapter over the 1st SimpleAdapter. but , it is getting overwritted and only the second list is being displayed.

I want to display both in a single list with different list format for each objects as list_item and list_item_new need help

    ListAdapter newAdapter = new SimpleAdapter(
                        NotificationTask.this, notificationsList,
                        R.layout.list_item_new, new String[] { TAG_PID,
                                TAG_NAME, TAG_DESCRIPTION},
                        new int[] { R.id.pid, R.id.name, R.id.description });

                newAdapter = new SimpleAdapter(
                          NotificationTask.this, oldNotificationsList,
                          R.layout.list_item, new String[] { TAG_NID,
                          TAG_NAME, TAG_DESCRIPTION},
                          new int[] { R.id.pid, R.id.name, R.id.description });

                //list.setAdapter(adapter);
                setListAdapter(newAdapter);

                        ((BaseAdapter) newAdapter).notifyDataSetChanged();

Solution

  • This is not possible, try to create a custom adapter able to handle both elements on the method getView (if one kind of view differs from the other).

    The adapter is a middle man between the listview and its content, so each listview is able to manage just one adapter, this is the reason why it gets overwriten by the data located on the second adapter.