Wireless Final Exam Answer Summer 2021

1-a ->> homefragment.xml

NOTE: Please change “nurnobi” to “yourname”

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#D6D6D6"
    tools:context=".Fragments.HomeFragment">

    <com.denzcoskun.imageslider.ImageSlider
        android:id="@+id/image_slider_nurnobi"
        android:layout_marginTop="50dp"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        app:iss_auto_cycle="true"
        app:iss_period="1000"
        app:iss_placeholder="@drawable/placeholder"
        app:iss_delay="0"/>

    <GridView
        android:background="#D6D6D6"
        android:layout_margin="10dp"
        android:id="@+id/gridView_nurnobi"
        android:horizontalSpacing="10dp"
        android:verticalSpacing="10dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/image_slider_nurnobi"
        android:layout_alignParentBottom="true"
        android:numColumns="2" />

</RelativeLayout>

3–>> b java Code

package com.nurnobishanto.finalexam.Fragments;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.denzcoskun.imageslider.ImageSlider;
import com.denzcoskun.imageslider.constants.ScaleTypes;
import com.denzcoskun.imageslider.models.SlideModel;
import com.nurnobishanto.finalexam.MainActivity;
import com.nurnobishanto.finalexam.R;

import java.util.ArrayList;
import java.util.List;


public class HomeFragment extends Fragment {
    ImageSlider imageSlider;
    List<SlideModel> slideModelList;
    private String[] homeMenu;
    private int[] menuIcon ={R.drawable.place,R.drawable.ta,R.drawable.timetravel,R.drawable.alert,R.drawable.connect,R.drawable.gallery};
    GridView gridView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        imageSlider = view.findViewById(R.id.image_slider_nurnobi);
        slideModelList= new ArrayList<>();
        slideModelList.add(new SlideModel(R.drawable.a,"", ScaleTypes.FIT));
        slideModelList.add(new SlideModel(R.drawable.b,"", ScaleTypes.FIT));
        slideModelList.add(new SlideModel(R.drawable.c,"", ScaleTypes.FIT));
        slideModelList.add(new SlideModel(R.drawable.bd,"", ScaleTypes.FIT));

        imageSlider.setImageList(slideModelList,ScaleTypes.FIT);


        gridView = (GridView) view.findViewById(R.id.gridView_nurnobi);
        homeMenu =getResources().getStringArray(R.array.menu_home);
        CustomAdapter adapter = new CustomAdapter(homeMenu,menuIcon,view.getContext());
        gridView.setAdapter(adapter);
        return view;
    }
    private class CustomAdapter extends BaseAdapter {

        String[] name;
        int[] icon;
        Context context;
        private LayoutInflater inflater;

        public CustomAdapter(String[] name, int[] icon, Context context) {
            this.name = name;
            this.icon = icon;
            this.context = context;
        }

        @Override
        public int getCount() {
            return name.length;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView==null){
                inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView= inflater.inflate(R.layout.menu_item_layout,parent,false);
            }
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //startActivity(context,"tis.".class);
                }
            });
            TextView nameText = convertView.findViewById(R.id.menuName);
            ImageView iconView = convertView.findViewById(R.id.menuImage);
            //  CardView item = convertView.findViewById(R.id.menuId);
            iconView.setImageResource(icon[position]);
            nameText.setText(name[position]);
            iconView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (position==0){
                        Toast.makeText(getContext(),"Visited Paces",Toast.LENGTH_LONG).show();
                    }
                    else if (position==1){

                        Toast.makeText(getContext(),"Current Goal",Toast.LENGTH_LONG).show();
                    }
                    else if (position==2){
                        Toast.makeText(getContext(),"Future plan",Toast.LENGTH_LONG).show();

                    }
                    else if (position==3){
                        Toast.makeText(getContext(),"Emergency",Toast.LENGTH_LONG).show();

                    }
                    else if (position==4){
                        Toast.makeText(getContext(),"Connections",Toast.LENGTH_LONG).show();


                    }
                    else if (position==5){

                        Toast.makeText(getContext(),"Gallery",Toast.LENGTH_LONG).show();

                    }


                }
            });


            return convertView;
        }
    }

}
Posted in Education