Gridview图像应链接到另一个活动

时间:2013-10-04 06:03:39

标签: android gridview

我提到了here来制作网格视图。现在我想要的是如果我在gridview中触摸一个图像,它应该将我链接到屏幕中的下一个活动。我的活动总共有5张图片,如果我触摸这些图片,每张图片都需要显示五种不同的活动。我试过this但是做不到我想要的。任何人都可以告诉我如何实现这一目标。提前致谢

2 个答案:

答案 0 :(得分:0)

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(mThumbIds[position]);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setLayoutParams(new GridView.LayoutParams(70, 70));

// USE this here and implement as acording by using 'position'
        imageView.setOnClickListener();
        return imageView;
    }

答案 1 :(得分:0)

使用Switch语句并根据位置进行更改。

     public void onCreate(Bundle savedInstanceState)
          {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.list);
            GridView gridview = (GridView) findViewById(R.id.gv);
            gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
             switch(position)
                {
                case 0:               
                    Intent ammissione = (new Intent(List.this, Ammissione.class));             
                    startActivity(ammissione);
                    break;

                case 1:
                    Intent organizzazione = (new Intent(List.this, Organizzazione.class));             
                    startActivity(organizzazione);
                    break;

                case 2:
                    Intent notizie = (new Intent(List.this, Notizie.class));             
                    startActivity(notizie);
                     break;
                case 3:
                    Intent percorsi = (new Intent(List.this, Percorsi.class));             
                    startActivity(percorsi);

                case 4:
                    Intent didattica = (new Intent(List.this, Didattica.class));             
                    startActivity(didattica);
                    break;

                }


        }
    });
  }