Last active
December 22, 2015 06:48
-
-
Save laaptu/6433023 to your computer and use it in GitHub Desktop.
Creating static handlers on Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CustomHandler customHandler = new CustomHandler(this); | |
customHandler.sendEmptyMessage(0); | |
static class CustomHandler extends Handler{ | |
private final WeakReference<FriendListFragment> fragmentHolder; | |
public CustomHandler(FriendListFragment friendListFragment){ | |
fragmentHolder = new WeakReference<FriendListFragment>(friendListFragment); | |
} | |
@Override | |
public void handleMessage(android.os.Message msg) { | |
final FriendListFragment friendListFragment = fragmentHolder.get(); | |
switch (msg.what) { | |
case 0: | |
Toast.makeText(friendListFragment.context, | |
"Sorry no groups/friends has been added", | |
Toast.LENGTH_SHORT).show(); | |
if (friendListFragment.mFriendListAdapter != null) { | |
friendListFragment.mFriendListAdapter.friendList.clear(); | |
friendListFragment.mFriendListAdapter.notifyDataSetChanged(); | |
friendListFragment.fragmentCommunicator.toggleVisibility(View.GONE); | |
} | |
break; | |
default: | |
break; | |
} | |
friendListFragment.showDialog(null); | |
friendListFragment.resetThreadCancelBoolean(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment