I have a snippet that contains a ListView . ListView I fill the adapter. In the new Task I fill out the ListView . In the adapter itself, I have to check for emptiness. I need to call a task in the fragment if the list is empty. I implement it like this:
public class FragmentAddFriends extends Fragment { View v; ListView listView; public ArrayList<myFriend> myFriendArrayList = new ArrayList<>(); ArrayList<String> friendses = new ArrayList<>(); AddFriendsAdapter adapter; ProgressBar progressBar; getAddFriendsTask task; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { v = inflater.inflate(R.layout.add_friends_fragment,container,false); listView = (ListView) v.findViewById(R.id.listViewAddFriends); progressBar = (ProgressBar) v.findViewById(R.id.progressBar2); adapter = new AddFriendsAdapter(getActivity(),myFriendArrayList); listView.setAdapter(adapter); //VKRequest zapros = VKApi.friends().get(VKParameters.from(VKApiConst.OWNER_ID, Integer.parseInt(VKAccessToken.currentToken().userId),VKApiConst.FIELDS,"photo_50")); task = new getAddFriendsTask(); task.execute(); return v; } @Override public void onStop() { super.onStop(); task.cancel(true); } public void update(){ task.execute(); button.setVisibility(View.Visible); } } When the method is called again in the fragment, the list is supplemented. That's how I call in the adapter:
if(list.size()==0){ fragment.update(); } But at the same time the method call is made, but the list is not updated. And the button also does not become visible.
Loaderclass and its descendants (likeAsyncTaskLoader). They are specifically designed for asynchronous populating of lists. - pavlofff