佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 794|回复: 2

Android Gridview里的item隐藏或显示

[复制链接]
发表于 21-2-2014 12:17 PM | 显示全部楼层 |阅读模式
当我点击第一的时候,假设第一的position为0,当代码运行完毕后,该汉字会在第二中显示,然后第一的图画和汉字都会隐藏,当我点击第二的position2时候,第一被隐藏的东西要出现。



private GridView Grid_Game, Grid_Game_Press;public static final String[] WORD = { "不", "流", "泪", "的", "机", "场", "你",
                        "我", "他", "山", "水", "老", "火", "谢", "上", "了", "拉", "大", "一", "要",
                        "爱", "广", "死", "话" };
public static String PRESS[] = {};
SimpleAdapter simpleAdapter;
public static int image1[] = { R.drawable.word1 };
public static int image2[] = { R.drawable.word2 };


protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

PRESS = new String[6];

//第一
Grid_Game = (GridView) findViewById(R.id.grid_game);
                Grid_Game.setAdapter(getAdapter(WORD, image1));

                Grid_Game.setOnItemClickListener(new OnItemClickListener() {
                        public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int position, long arg3) {
                                for (i = 0; PRESS != null; i++) {
                                }
                                switch (position) {
                                case 0:
                                        PRESS = WORD[position];
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        arg1.setVisibility(View.GONE);
                                        break;
                                case 1:
                                        PRESS = WORD[position];
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;

                                case 2:
                                        PRESS = WORD[position];
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;

                                case 3:
                                        PRESS = WORD[position];
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;

                                             ... ... ...
                                             ... ... ...
                                             ... ... ...
                                case 23:
                                        PRESS = WORD[position];
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;

                                }
                        }
                });

//第二
Grid_Game_Press = (GridView) findViewById(R.id.grid_game_word);
                Grid_Game_Press.setNumColumns(6);
                Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                // 已选的答案
                Grid_Game_Press.setOnItemClickListener(new OnItemClickListener() {
                        public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int position2, long arg3) {
                                switch (position2) {
                                case 0:
                                        PRESS[position2] = null;
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;
                                case 1:
                                        PRESS[position2] = null;
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;
                                case 2:
                                        PRESS[position2] = null;
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;
                                case 3:
                                        PRESS[position2] = null;
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;
                                case 4:
                                        PRESS[position2] = null;
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;
                                case 5:
                                        PRESS[position2] = null;
                                        Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        break;
                                }
                        }
                });




public SimpleAdapter getPress(String[] pressword, int[] image) {
                ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
                for (int i = 0; i < pressword.length; i++) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("IMAGE", image[0]);
                        map.put("WORD", pressword);
                        data.add(map);
                }
                simpleAdapter = new SimpleAdapter(this, data, R.layout.griditem_level,
                                new String[] { "IMAGE", "WORD" }, new int[] { R.id.image_level,
                                                R.id.text_level });
                return simpleAdapter;
        }

        public SimpleAdapter getAdapter(String[] word, int[] image) {
                ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
                for (int i = 0; i < word.length; i++) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        map.put("IMAGE", image[0]);
                        map.put("WORD", word);
                        data.add(map);
                }
                simpleAdapter = new SimpleAdapter(this, data, R.layout.griditem_level,
                                new String[] { "IMAGE", "WORD" }, new int[] { R.id.image_level,
                                                R.id.text_level });
                return simpleAdapter;
        }



}


回复

使用道具 举报


ADVERTISEMENT

发表于 22-2-2014 01:52 AM | 显示全部楼层
请问你用什么software来complie?
回复

使用道具 举报

 楼主| 发表于 22-2-2014 10:22 AM | 显示全部楼层
鋼鐵狂神 发表于 22-2-2014 01:52 AM
请问你用什么software来complie?

Eclipse     
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 1-11-2025 06:23 AM , Processed in 0.115416 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表