Created
January 23, 2012 21:34
-
-
Save jasonpolites/1665636 to your computer and use it in GitHub Desktop.
Reload Action Bar With Create Entity
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
// Create a class to handle the callback from the action bar | |
public class MyActionBarListener implements ActionBarListener { | |
private ActionBarView actionBarView; | |
@Override | |
public void onCreate(ActionBarView actionBar) { | |
// Store a reference to the actionBar view | |
this.actionBarView = actionBar; | |
} | |
public ActionBarView getActionBarView() { | |
return actionBarView; | |
} | |
} | |
// In the activity that renders the action bar, set the listener | |
public class ActionBarReloadActivity extends Activity { | |
// Setup a listener to retain a reference | |
MyActionBarListener listener = new MyActionBarListener(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
String entityKey = "your_key"; | |
// Use the listener when you show the action bar | |
SocializeUI.getInstance().showActionBar(this, R.layout.your_layout, entityKey, listener); | |
} | |
} | |
// Later (After the action bar has loaded!), you can reference the view to refresh | |
final ActionBarView view = listener.getActionBarView(); | |
if(view != null) { | |
Socialize.getSocialize().addEntity("new_entity", "new_entity_name", new EntityAddListener() { | |
@Override | |
public void onError(SocializeException error) { | |
// Handle error | |
} | |
@Override | |
public void onCreate(Entity entity) { | |
view.setEntityKey(entity.getKey()); | |
view.refresh(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment