Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- private DrawerLayout mDrawer ;
- private ActionBarDrawerToggle mToggle;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mDrawer = (DrawerLayout) findViewById(R.id.drawer);
- mToggle = new ActionBarDrawerToggle(this,mDrawer,R.string.open,R.string.close);
- mDrawer.addDrawerListener(mToggle);
- NavigationView nvDrawer = (NavigationView) findViewById(R.id.nv);
- mToggle.syncState();
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setupDrawerContent(nvDrawer);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (mToggle.onOptionsItemSelected(item)){
- return true ;
- }
- return super.onOptionsItemSelected(item);
- }
- public void selectItemDrawer(MenuItem menuItem){
- Fragment myFragment = null;
- Class fragmentclass;
- switch (menuItem.getItemId()){
- case R.id.drive:
- fragmentclass = Driving.class;
- break;
- case R.id.test:
- fragmentclass = Tests.class;
- break;
- case R.id.rules:
- fragmentclass = Rules.class;
- break;
- case R.id.sign:
- fragmentclass = Road.class;
- break;
- case R.id.faq:
- fragmentclass = faq.class;
- break;
- case R.id.like:
- fragmentclass = llike.class;
- break;
- default:
- fragmentclass = faq.class;
- }
- try {
- myFragment = (Fragment) fragmentclass.newInstance();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- FragmentManager fragmentManager = getSupportFragmentManager();
- fragmentManager.beginTransaction().replace(R.id.lt,myFragment).commit();
- menuItem.setChecked(true);
- setTitle(menuItem.getTitle());
- mDrawer.closeDrawers();
- }
- private void setupDrawerContent (NavigationView navigationView){
- navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
- @Override
- public boolean onNavigationItemSelected(@NonNull MenuItem item) {
- selectItemDrawer(item);
- return true;
- }
- });
- }
- }
- `
- public class Tests extends Fragment {
- // TODO: Rename parameter arguments, choose names that match
- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
- private static final String ARG_PARAM1 = "param1";
- private static final String ARG_PARAM2 = "param2";
- // TODO: Rename and change types of parameters
- private String mParam1;
- private String mParam2;
- private OnFragmentInteractionListener mListener;
- public Tests() {
- // Required empty public constructor
- }
- /**
- * Use this factory method to create a new instance of
- * this fragment using the provided parameters.
- *
- * @param param1 Parameter 1.
- * @param param2 Parameter 2.
- * @return A new instance of fragment Tests.
- */
- // TODO: Rename and change types and number of parameters
- public static Tests newInstance(String param1, String param2) {
- Tests fragment = new Tests();
- Bundle args = new Bundle();
- args.putString(ARG_PARAM1, param1);
- args.putString(ARG_PARAM2, param2);
- fragment.setArguments(args);
- return fragment;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getArguments() != null) {
- mParam1 = getArguments().getString(ARG_PARAM1);
- mParam2 = getArguments().getString(ARG_PARAM2);
- }
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View view = inflater.inflate(R.layout.fragment_tests, container, false);
- Button btnV = (Button) view.findViewById(R.id.Vehicle);
- Button btnM = (Button) view.findViewById(R.id.Bike);
- Button btnT = (Button) view.findViewById(R.id.Truck);
- btnV.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Intent i = new Intent(getActivity(), VehicleActivity.class);
- startActivity(i);
- }
- });
- btnM.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Intent i = new Intent(getActivity(), MotorbikeActivity.class);
- startActivity(i);
- }
- });
- btnT.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Intent i = new Intent(getActivity(), TruckActivity.class);
- startActivity(i);
- }
- });
- return view;
- }
- // TODO: Rename method, update argument and hook method into UI event
- public void onButtonPressed(Uri uri) {
- if (mListener != null) {
- mListener.onFragmentInteraction(uri);
- }
- }
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- }
- @Override
- public void onDetach() {
- super.onDetach();
- mListener = null;
- }
- /**
- * This interface must be implemented by activities that contain this
- * fragment to allow an interaction in this fragment to be communicated
- * to the activity and potentially other fragments contained in that
- * activity.
- * <p>
- * See the Android Training lesson <a href=
- * "http://developer.android.com/training/basics/fragments/communicating.html"
- * >Communicating with Other Fragments</a> for more information.
- */
- public interface OnFragmentInteractionListener {
- // TODO: Update argument type and name
- void onFragmentInteraction(Uri uri);
- }
- }
- <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/drawer"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="com.maiweb.mohammed.vayasa.MainActivity">
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/lt"
- >
- <TextView
- android:id="@+id/textView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:fontFamily="cursive"
- android:text="About Us
- "
- android:textSize="36sp" />
- <TextView
- android:id="@+id/textView6"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentStart="true"
- android:layout_below="@+id/textView2"
- android:text="Vaya SA is an application that is aimed at providing a learner’s licence test simulation as well as providing you with names of accredited driving schools in your area."
- android:textStyle="bold" />
- </RelativeLayout>
- <android.support.design.widget.NavigationView
- android:id="@+id/nv"
- app:headerLayout="@layout/header"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- app:menu="@menu/drawermenu"
- android:layout_gravity="start"
- >
- </android.support.design.widget.NavigationView>
- </android.support.v4.widget.DrawerLayout>
- `<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="com.maiweb.mohammed.vayasa.Tests">
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Please Choose the test you would like to take"
- android:textColor="#0000ff"
- android:textSize="40sp" />
- <Button
- android:id="@+id/Vehicle"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignStart="@+id/Bike"
- android:layout_below="@+id/Bike"
- android:layout_marginTop="15dp"
- android:background="@drawable/background_round_corner_button"
- android:text="Vehicle Test" />
- <Button
- android:id="@+id/Bike"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignStart="@+id/Truck"
- android:layout_below="@+id/Truck"
- android:layout_marginTop="13dp"
- android:background="@drawable/background_round_corner_button"
- android:text="Motorbike Test" />
- <Button
- android:id="@+id/Truck"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentEnd="true"
- android:layout_below="@+id/textView"
- android:layout_marginTop="68dp"
- android:background="@drawable/background_round_corner_button"
- android:text="Truck Test" />
- </RelativeLayout>
Add Comment
Please, Sign In to add comment