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
public abstract class MFragmentActivity extends FragmentActivity { | |
protected abstract Fragment createFragment(); | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_fragment); | |
FragmentManager fm = getSupportFragmentManager(); | |
Fragment fragment = fm.findFragmentById(R.id.fragmentContainer); | |
if (fragment == null) { | |
fragment = createFragment(); // createFragment() the implemented method | |
fm.beginTransaction().add(R.id.fragmentContainer, fragment).commit(); |
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
public class MActivity extends MFragmentActivity { | |
//simple case | |
protected Fragment createFragment(){ return new MFragment();} // no need for MFragment to have newInstance() | |
// -or- if your fragment needs data (see MListFragment for the explicit Intent call) | |
// call the Activity with Intent; pass along extra (UUID in this template) for arg to MFragment | |
protected Fragment createFragment() { | |
UUID data = (UUID)getIntent().getSerializableExtra(MFragment.EXTRA_M_ID); | |
return MFragment.newInstance(id);} | |
} |
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
public class MFragment extends Fragment { | |
private DataObject mDataObject; | |
public static final String EXTRA_M_ID = "com.your.apps.extra_id"; | |
public static MFragment newInstance(UUID id) { // set the args | |
Bundle args = new Bundle(); | |
args.putSerializable(EXTRA_M_ID, id); | |
MFragment fragment = new MFragment(); | |
fragment.setArguments(args); | |
return fragment;} | |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); |
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
public class MListFragment extends ListFragment { private static final String TAG = "MListFragment"; | |
private ArrayList<DataObject> mArrayList; | |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); | |
mArrayList = DataStoreSingleton.get(getActivity()).getObjects(); | |
MAdapter adapter = new MAdapter(mArrayList); | |
setListAdapter(adapter); } // ListFragment METHOD | |
private class MAdapter extends ArrayAdapter<DataObject> { | |
public MAdapter(ArrayList<DataObject> mArrayList) { super(getActivity(), 0, mArrayList); } | |
public View getView(int position, View convertView, ViewGroup parent){ |
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
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { | |
View v = inflater.inflate(R.layout.fragment_m, parent, false); | |
//Button | |
mButton = (Button) v.findViewById(R.id.data_date); | |
mButton.setText(object.getDate().toString()); // mDateButton.setEnabled(false); | |
mButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
} | |
}); |
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
// calling class: | |
//FragmentManager fm = getActivity().getSupportFragmentManager(); | |
//MDialogFragment mDialogFragment = MDialogFragment.newInstance(object.getDate()); | |
//mDialogFragment.setTargetFragment(MFragment.this, REQUEST_DATE); | |
//mDialogFragment.show(fm, DIALOG_DATE); |
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
extends ListFragment { | |
private boolean mSubtitleVisible; //instance vbl retained | |
onCreate... | |
setHasOptionsMenu(true); //Fragment will be implementing options menu callbacks on behalf of the activity. | |
setRetainInstance(true); //retain | |
mSubtitleVisible = false; //retain is for preserving menu state through rotation event | |
@TargetApi(11) // if ( minSdk < API < 11) !Lint; you have accounted for VERSION_CODE and under | |
onCreateView... |
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
android:theme="@android:style/Theme.Holo"> | |
Toast.makeText(getContext(), text/resId, Toast.LENGTH_SHORT).show(); | |
$ ./gradlew tasks | |
$ ./gradlew installDebug |
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
private static final String KEY_VAL = "valofit"; | |
private static final String KEY_TRUE = "isittrue"; | |
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); | |
if (savedInstanceState != null) { | |
mCurrentVal = savedInstanceState.getInt(KEY_VAL, 0); | |
mIsTrue = savedInstanceState.getBoolean(KEY_TRUE, false); | |
public void onSaveInstanceState(@NonNull Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); | |
savedInstanceState.putInt(KEY_VAL, mCurrentVal); |
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
config = { //SAMPLE OBJECT - replace this with your data object | |
stroke: 2, //svg stroke value | |
opacity: 0.3, //0-1 | |
offsetX: 120, //px | |
offsetY: 80, | |
fontWeight: 400, //css font-weight | |
fontSize: 12, //in px | |
changePositive: '\u25B4', //unicode character for up arrow | |
changeNegative: '\u25BE', //unicode character for down arrow | |
colorBlue: '#1190A3', //all hex colors will automatically use the addColor dat gui function |
OlderNewer