Skip to main content

Posts

Showing posts with the label fragment

How to implement a fragment in Android

 We can call fragment as a sub activity. By using fragment navigation will more easier and in tabs layouts look cool.Let us see an example..... Here we have 2 fragment class Details, and Detail2. MainActivity.java import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Here we call the first fragment Fragment fragment = null; fragment = new Options(); FragmentTransaction fragmentTransaction = getFragmentManager() .beginTransaction(); fragmentTransaction.replace(R.id.frame1, fragment).commit(); } } Options.java import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.os.Bundle; import android.view.LayoutInflater; import android.view....