Android Fragment - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Fragment class.

This code example shows how to use the following methods:
 
import static android.support.v4.app.Watson.OnCreateOptionsMenuListener; 
import static android.support.v4.app.Watson.OnOptionsItemSelectedListener; 
import static android.support.v4.app.Watson.OnPrepareOptionsMenuListener; 
 
public class SherlockFragment extends Fragment implements OnCreateOptionsMenuListener, OnPrepareOptionsMenuListener, OnOptionsItemSelectedListener {
    private SherlockFragmentActivity mActivity;
 
    public SherlockFragmentActivity getSherlockActivity() { 
        return mActivity;
    } 
 
    @Override 
    public void onAttach(Activity activity) {
        if (!(activity instanceof SherlockFragmentActivity)) {
            throw new IllegalStateException(getClass().getSimpleName() + " must be attached to a SherlockFragmentActivity.");
        } 
        mActivity = (SherlockFragmentActivity)activity;
 
        super.onAttach(activity);
10
CodeRank
This code example shows how to use the following methods:setRetainInstance
	 
	public ColorFragment() {  
		this(R.color.white);
	} 
	 
	public ColorFragment(int colorRes) {
		mColorRes = colorRes;
		setRetainInstance(true);
	} 
 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		if (savedInstanceState != null)
			mColorRes = savedInstanceState.getInt("mColorRes");
		int color = getResources().getColor(mColorRes);
		// construct the RelativeLayout 
		RelativeLayout v = new RelativeLayout(getActivity());
		v.setBackgroundColor(color);		
		return v;
	} 
10
CodeRank
This code example shows how to use the following methods:
package com.newsblur.fragment; 
 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
 
import com.newsblur.R; 
 
public class LoadingFragment extends Fragment {
	 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_loadingitems, null);
	} 
 
} 

10
CodeRank
This code example shows how to use the following methods:
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 
 
package com.actionbarsherlock.sample.fragments; 
 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentTransaction; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.TextView; 
import com.actionbarsherlock.app.SherlockFragment; 
import com.actionbarsherlock.app.SherlockFragmentActivity; 
10
CodeRank
This code example shows how to use the following methods:setRetainInstance
  public ContentFragment() { 
    this(null); 
  } 
   
  public ContentFragment(String url) {
    super(); 
     
    urlToLoad=url;
    setRetainInstance(true);
  } 
   
  @Override 
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                            Bundle savedInstanceState) {
    return(inflater.inflate(R.layout.content_fragment, container, false));
  } 
   
  @Override 
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
10
CodeRank
This code example shows how to use the following methods:
 
import com.newsblur.R; 
import com.newsblur.view.StateToggleButton; 
import com.newsblur.view.StateToggleButton.StateChangedListener; 
 
public class FeedIntelligenceSelectorFragment extends Fragment implements StateChangedListener {
	 
	public static final String FRAGMENT_TAG = "feedIntelligenceSelector";
	private StateToggleButton button;
	 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_intelligenceselector, null);
		button = (StateToggleButton) v.findViewById(R.id.fragment_intelligence_statebutton);
		button.setStateListener(this);
		return v;
	} 
 
	@Override 
	public void changedState(int state) {
10
CodeRank
This code example shows how to use the following methods:setRetainInstance, setUserVisibleHint
public class SupportSelectionStateFragment extends Fragment implements SelectionState {
 
  private CommonSelectionStateFragment _common = new CommonSelectionStateFragment();
 
  public SupportSelectionStateFragment() { 
    super(); 
    setRetainInstance(true);
    setUserVisibleHint(false);
  } 
 
  @Override 
  public void onSaveInstanceState(final Bundle state) {
    super.onSaveInstanceState(state);
    _common.onSaveInstanceState(state);
  } 
 
  @Override 
  public void onCreate(final Bundle state) {
    super.onCreate(state);
    _common.onCreate(state);
10
CodeRank
This code example shows how to use the following methods:
import org.androidannotations.annotations.OptionsMenu; 
import org.androidannotations.test15.R; 
 
@EFragment 
@OptionsMenu({R.menu.my_menu, R.menu.my_menu2}) 
public class OptionsMenuSupportFragment extends Fragment { 
	 
	@OptionsItem 
	void menuRefreshSelected() { 
	} 
 
	@OptionsItem({ R.id.menu_search, R.id.menu_share }) 
	boolean multipleMenuItems() { 
		return false; 
	} 
 
	@OptionsItem 
	void menu_add(MenuItem item) { 
	} 
 
10
CodeRank
This code example shows how to use the following methods:
import android.widget.TextView; 
 
/** 
 * Stub class that can be used for testing support-lib fragments. 
 */ 
public class CustomFragment extends Fragment {
 
  private TextView textView;
 
  @Override 
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    textView = new TextView(inflater.getContext());
    textView.setText("CustomFragment text view");
    return textView;
  } 
} 
10
CodeRank
This code example shows how to use the following methods:setRetainInstance
import android.view.ViewGroup; 
import android.widget.TextView; 
 
public class NewFragment extends Fragment {
 
	public NewFragment(){ 
		setRetainInstance(true);
	} 
	 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.main_page_layout, null);
		TextView textView = (TextView)view.findViewById(R.id.tv_text);
		textView.setText("This is a new fragment");
		return view;
	} 
 
	@Override 
	public void onCreate(Bundle savedInstanceState) {
10
CodeRank

Related Android Fragment Questions & Answers:

See Code Examples for Android Fragment Methods: