package br.com.androidzin.launchablesitens;

import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.ActionBar.TabListener;
import com.actionbarsherlock.app.SherlockListFragment;

public abstract class FragmentInfo extends SherlockListFragment implements TabListener {

	private Fragment mFragment;
	private static final String TAG = "Tab";
	private List<LaunchableItem> data;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		if(data == null) data = getSampleData();
		ArrayAdapter<LaunchableItem> adapter = new LaunchableItemAdapter(getActivity(), R.layout.item, this.data, (OnItemCheckedListener) getActivity());
		setListAdapter(adapter);
		return super.onCreateView(inflater, container, savedInstanceState);
	}
	
	protected abstract List<LaunchableItem> getSampleData();
	
	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		Log.d(TAG, "OnTabReselected");
		
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		Log.d(TAG, "OnTabSelected");
		
		if (mFragment == null) {
			try {
				mFragment = this.getClass().newInstance();
			} catch (java.lang.InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
			  ft.add(android.R.id.content, mFragment);
        } else {
            ft.attach(mFragment);
        }
      
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		Log.d(TAG, "OnTabUnselected");
		if(mFragment != null){
			ft.detach(mFragment);
		}
	}

	public List<LaunchableItem> getData() {
		return data;
	}

	public void setData(List<LaunchableItem> data) {
		this.data = data;
	}
	
	
	
}

@@ -62,16 +62,45 @@
 .List;%0A%0A
+import android.app.Activity;%0A
 import a
@@ -463,24 +463,185 @@
 abListener;%0A
+import com.actionbarsherlock.app.SherlockActivity;%0Aimport com.actionbarsherlock.app.SherlockFragment;%0Aimport com.actionbarsherlock.app.SherlockFragmentActivity;%0A
 import com.a
@@ -1567,19 +1567,16 @@
 cted%22);%0A
-%09%09%0A
 %09%09if (mF
@@ -1802,16 +1802,18 @@
 %0A%09%09%09
-  
 ft.
-add
+replace
 (and

Fix Rotation Error