0

What i am trying to do is that when the activity is opened, the content will start loading/fethcing in a listview "automatically". I'm using the simple facebook library to fetch a list of friends, right now i have a button that fetches the content to the listview, but i would like to make it load automatically.

Here is the activity:

@Override
public void onResume() {
    super.onResume();
    mSimpleFacebook = SimpleFacebook.getInstance(this);
}

    final OnFriendsListener mOnFriendsListener = new OnFriendsListener() {

        @Override
        public void onFail(String reason) {
            hideDialog();
            toast("You are not logged in");
            Log.w(TAG, reason);
        }

        @Override
        public void onException(Throwable throwable) {
            hideDialog();
            toast("Error");
            Log.e(TAG, "Bad thing happened", throwable);
        }

        @Override
        public void onComplete(List<Profile> friends) {
            // populate list
            List<String> values = new ArrayList<String>();
            for (Profile profile : friends) {
                //profile.getInstalled();
                values.add(profile.getName());
            }
            ArrayAdapter<String> friendsListAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);
            mFriendsList.setAdapter(friendsListAdapter);
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        mSimpleFacebook.onActivityResult(this, requestCode, resultCode, data); 
        super.onActivityResult(requestCode, resultCode, data);
    } 

Here is the button that loads the content:

mButtonGetFriends = (Button) findViewById(R.id.button_get_friends);
        mButtonGetFriends.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSimpleFacebook.getFriends(mOnFriendsListener); 
            }   
        });

How can i make the content load automatically when the activity is opened, without clicking a button?

da_st
  • 402
  • 2
  • 10
  • 27

0 Answers0