Skip to content

Instantly share code, notes, and snippets.

@jyaunches
jyaunches / gist:3791264
Created September 26, 2012 23:26
Fragment activity's layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.myproject.activities.SomeFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/some_fragment"/>
</LinearLayout>
private void configureActionBarTabs() {
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.addTab(actionBar.newTab()
.setIcon(R.drawable.puppies)
.setTabListener(new TabListener<PuppyFragment>(this, "PUPPIES", PuppyFragment.class)));
actionBar.addTab(actionBar.newTab()
.setIcon(R.drawable.rainbows)
.setTabListener(new TabListener<RainbowsFragment>(this, "RAINBOWS", RainbowsFragment.class)));
actionBar.addTab(actionBar.newTab()
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/some_fragment_container"/>
@InjectFragment(id.some_fragment)
private SomeFragment someFragment;
@jyaunches
jyaunches / gist:3791296
Created September 26, 2012 23:33
Retrieving fragment as any other layout
public class SomeActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SomeFragment someFragment = (SomeFragment)findViewById(id.some_fragment);
}
}
SomeFragment someFragment = new SomeFragment();
FragmentManager supportFragmentManager = context.getFragmentManager();
FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.some_fragment_container, someFragment, "SOME_FRAGMENT_TAG");
fragmentTransaction.addToBackStack("SOME_FRAGMENT_TAG");
fragmentTransaction.commit();
public class SendMessageTask extends SafeAsyncTask<Boolean> {
private final HttpClient httpClient;
private final sendMessageCallbacks sendMessageCallbacks;
@Inject
public SendMessageTask(org.apache.http.client.HttpClient httpClient,
@Assisted SendMessageCallbacks sendMessageCallbacks {
this.httpClient = httpClient;
this.sendMessageCallbacks = sendMessageCallbacks;
}
public class SendMessageTask extends SafeAsyncTask<Boolean> {
private final EventBus eventBus;
@Inject
public EndSessionTask(EventBus eventBus) {
this.eventBus = eventBus;
}
@Override
public Boolean call() throws Exception {
import com.google.common.eventbus.Subscribe;
public class MessagingActivity extends Activity {
//activity setup methods
public void sendMessage(){
new SendMessageTask(httpClient, this).execute();
}
public class MessagingActivity implements SendMessageCallbacks extends Activity {
//activity setup methods
public void sendMessage(){
new SendMessageTask(httpClient, this).execute();
}
@Override
protected void onMessageSendingFailed(String reason) {