Are you adding and removing ListViews? If so, that's the wrong approach. When the new data comes in from the server, you need to operate on the Adapter to refresh the data. Something like
function void onLoadFinished( List<?> myObjects )
{
this.adapter.clear();
this.adapter.addAll( myObjects );
}
This will instantly clear the list and add your new data. Constructing the ListView each time is not the way to go.
Also, you probably should consider using the Loader framework, as it will handle all of the AsyncTask stuff for you. I learned the pattern using a ADP's excellent examples here.
Also, make sure you're extending ListFragment. If so, your layout needs to have a ListView
in it that has the id @id/android:list
, then just set it in the onCreateView
method. Here's an example XML:
<!DOCTYPE android>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFFFF" >
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:cacheColorHint="#FDFFCE" />
<Spinner
android:id="@+id/location_spinner"
android:layout_width="56dp"
android:layout_height="1px"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:textColor="#FF000000"
android:visibility="invisible" />
<Spinner
android:id="@+id/area_spinner"
android:layout_width="wrap_content"
android:layout_height="1px"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/location_type_spinner"
android:gravity="center"
android:textColor="#FF000000"
android:visibility="invisible" />
</RelativeLayout>
then the view is inflated here:
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState )
{
View view = inflater.inflate( R.layout.fragment_location_list, null );
return view;
}
I do all additional setup and view binding in onActivityCreated:
@Override
public void onActivityCreated( Bundle savedInstanceState )
{
super.onActivityCreated( savedInstanceState );
setRetainInstance( true );
LayoutInflater.from( getActivity() );
getListView().setDividerHeight( 1 );
getListView().setOnCreateContextMenuListener( this );
getListView().setOnItemLongClickListener( this );
getListView().setFocusable( true );
getListView().setOnTouchListener( this );
.
.
.
}
That should take care of all the FragmentActivity lifecycle events for you.