If you think the Android project infinitep listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package es.daconstenla.infinip.customcomponents;
//fromwww.java2s.comimport android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
publicclass MonthFragmentTest extends Fragment {
/**
* Key to insert the background color into the mapping of a Bundle.
*/privatestaticfinal String BACKGROUND_COLOR = "color";
/**
* Key to insert the index page into the mapping of a Bundle.
*/privatestaticfinal String INDEX = "index";
privateint color;
privateint index;
/**
* Instances a new fragment with a background color and an index page.
*
* @param color
* background color
* @param index
* index page
* @return a new page
*/publicstatic MonthFragmentTest newInstance(int color, int index) {
// Instantiate a new fragment
MonthFragmentTest fragment = new MonthFragmentTest();
// Save the parameters
Bundle bundle = new Bundle();
bundle.putInt(BACKGROUND_COLOR, color);
bundle.putInt(INDEX, index);
fragment.setArguments(bundle);
fragment.setRetainInstance(true);
return fragment;
}
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Load parameters when the initial creation of the fragment is done
this.color = (getArguments() != null) ? getArguments().getInt(
BACKGROUND_COLOR) : Color.GRAY;
this.index = (getArguments() != null) ? getArguments().getInt(INDEX)
: -1;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(es.daconstenla.infinip.R.layout.fragment_text, container, false);
// Show the current page index in the view
TextView tvIndex = (TextView) rootView.findViewById(es.daconstenla.infinip.R.id.tvIndex);
tvIndex.setText(String.valueOf(this.index));
// Change the background color
rootView.setBackgroundColor(this.color);
return rootView;
}
}