Skip to main content

Posts

Showing posts with the label fragment example

android fragment example

In this post i am going to present a simple example about fragments in android. In this example there are  two fragments presents, and add them into the main activity using two separate relative layouts. There are two buttons on the main activity, first button is for open the first fragment and by clicking the second button user can open the second fragment. Ads By Google MainActivity.java 1: public class MainActivity extends Activity { 2: Button B1,B2; 3: @Override 4: protected void onCreate(Bundle savedInstanceState) { 5: super.onCreate(savedInstanceState); 6: setContentView(R.layout.activity_main); 7: B1 = (Button)findViewById(R.id.b1); 8: B2 = (Button)findViewById(R.id.b2); 9: B1.setOnClickListener(new OnClickListener() { 10: @Override 11: public void onClick(View arg0) { 12: FragmentManager FM = getFragmentManager(); 13: ...