I am trying to show a toast when click on a button that button request’s a listener. I am logging out through this button and i want to show toast on loggout completion so i put toast in onComplete method of request Listener. Here is my complete code
HomeActivity which contains button listeners
public class HomeActivity extends Activity implements OnClickListener{
private static final String TAG = "Facebook";
private Button mLogin, mLogout, mShare;
private Facebook facebook;
private AsyncFacebookRunner abRunner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_home);
//mLogin.setBackgroundColor(Color.BLUE);
// Initialize facebook objects
facebook = new Facebook("479652662068145");
abRunner = new AsyncFacebookRunner(facebook);
// Setup VIews
mLogin= (Button) findViewById(R.id.Login);
mLogout= (Button) findViewById(R.id.Logout);
mLogin.setOnClickListener(this);
mLogout.setOnClickListener(this);
}
@Override
public void onClick(View v){
int id = v.getId();
switch(id){
case R.id.Login:
FacebookLoginDialog login = new FacebookLoginDialog();
facebook.authorize(this, login);
break;
case R.id.Logout:
FacebookLogoutRequest logout = new FacebookLogoutRequest(this);
abRunner.logout(this, logout);
break;
default:
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_home, menu);
return true;
}
}
And my RequestListener Code
public class FacebookLogoutRequest implements RequestListener{
private Context context;
public FacebookLogoutRequest (Context context){
this.context= context;
}
public void onComplete(String response, Object state) {
Toast toast = Toast.makeText(context, "You Are Logged Out", Toast.LENGTH_SHORT);
toast.show();
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
Please Help I am stuck here..Thanks
Use Activity instead of Context because context is not for UI reference