I have one activity that holds multiple fragments. Each fragment implements my UpdateRequest interface, where each of these fragments do some asynctask and downloads data from web service. My problem is that I don't really understand how to update existing fragments. I read this
Android Refreshing Fragment View after AsyncTask
but I still can't figure out how to locate views of each fragment and then update them. I'll give an example:
There's an UserFragment, which should represents user profile:
public class UserFragment extends SherlockFragment implements
UpdateRequest {
View rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_user_info,
container, false);
return rootView;
}
...
public void update(final OnFragmentUpdatedListener context) {
...
asyntask
...
}
}
And fragment_user_info looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/fragment_user_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/image_of_user" />
<TextView
android:id="@+id/fragment_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user_info" />
</RelativeLayout>
What I want is to locate instance of UserFragment and then in its AsyncTask.onPostExecute() method change text in fragment_user_name textView to something that asynctask returns.