1. AC Question's Avatar
    Code:
    package com.example.avancertech.location;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.content.Context;
    import android.view.Display;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.WindowManager;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.BaseAdapter;
    import android.widget.GridView;
    import android.widget.ImageView;
    import android.widget.Toast;
    
    import java.util.ArrayList;
    
    import java.util.List;
    
    public class Main2Activity extends AppCompatActivity {
    
        int[] gridViewImageId = {
    
                R.drawable.o1,R.drawable.a1, R.drawable.b1, R.drawable.white, R.drawable.c1, R.drawable.d1, R.drawable.white,
                R.drawable.e1,R.drawable.f1,R.drawable.white,R.drawable.g1,R.drawable.h1,R.drawable.white,
                R.drawable.i1,
    
                R.drawable.o2,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o3,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green, //FIRST 5
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green, //FIRST 10
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green, //FIRST 15
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green,
    
                R.drawable.o1,R.drawable.green, R.drawable.green, R.drawable.white, R.drawable.yellow, R.drawable.yellow, R.drawable.white,
                R.drawable.green,R.drawable.green,R.drawable.white,R.drawable.yellow,R.drawable.yellow,R.drawable.white,
                R.drawable.green, //FIRST 20
    
        };
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main2);
            String loc = getIntent().getStringExtra("LISTNAME");
            getSupportActionBar().setTitle(loc);
    
            GridView gridView = (GridView) findViewById(R.id.gridview);
            Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    
            int gridSize = display.getWidth();
            int count = gridSize / 120;
            int colWidth = (gridSize / count);
            gridView.setColumnWidth(colWidth);
            gridView.setNumColumns(count);
    
            gridView.setAdapter(new ImageAdapter(this));
    
            gridView.setOnItemClickListener(new OnItemClickListener()
            {
    
                public void onItemClick(AdapterView<?> parent,
                                        View v, int position, long id)
                {
                   /* ImageAdapter i = (ImageAdapter)parent.getAdapter();
                    Imageview
    
                    Toast.makeText(Main2Activity.this, "" + i.getItemId(position), Toast.LENGTH_SHORT).show();*/
    
                }
            });
    
        }
    
        public class ImageAdapter extends BaseAdapter
        {
    
            private static final int WHITE = 0;
            private static final int TEAL = 1;
            private static final int MAROON = 2;
            private List<Integer> mStates = new ArrayList<Integer>();
            private Context context;
    
            public ImageAdapter(Context c)
            {
                context = c;
            }
    
            public int getCount() {
                return gridViewImageId.length;
            }
    
            public Object getItem(int position) {
                return position;
            }
    
            public long getItemId(int position) {
                return position;
            }
    
            //---returns an ImageView view---
            public View getView(int position, View convertView, ViewGroup parent)
            {
    
                ImageView imageView;
                if (convertView == null) {
                    imageView = new ImageView(context);
                    imageView.setLayoutParams(new GridView.LayoutParams(28, 28));
                    imageView.setScaleType(ImageView.ScaleType.FIT_END);
                    imageView.setPadding(0, 0, 0, 0);
    
                } else {
                    imageView = (ImageView) convertView;
    
                }
    
                imageView.setImageResource(gridViewImageId[position]);
                return imageView;
    
            }
    
        }
    
    }
    02-06-2017 01:23 AM

Similar Threads

  1. Replies: 2
    Last Post: 02-06-2017, 05:19 PM
  2. I know in Pixel forum they will call me crazy but....
    By Phonejock in forum OnePlus 3 & 3T
    Replies: 4
    Last Post: 02-06-2017, 08:43 AM
  3. Trojan detected in android! What should i do?
    By Tof04548159 in forum General Help and How To
    Replies: 2
    Last Post: 02-06-2017, 08:42 AM
  4. How do you insert a sim card into a Samsung Gear S2 watch?
    By AC Question in forum Ask a Question
    Replies: 1
    Last Post: 02-06-2017, 02:45 AM
  5. How do I activate DND for one hour or two hours; 7.0 on S7
    By AC Question in forum Ask a Question
    Replies: 0
    Last Post: 02-06-2017, 01:04 AM
LINK TO POST COPIED TO CLIPBOARD