用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

请选择技术分类

 *如果你找不到更细的分类,可以选择上级分类
当前位置:云代码 - 技术问答 - Java

Android Gridview里的item显示或隐藏

 悬赏:10|提问者:征隆|浏览:6369
举报|2014-02-21
当我点击第一的时候,假设第一的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[i] != null; i++) {
}
switch (position) {
case 0:
PRESS[i] = WORD[position];
Grid_Game_Press.setAdapter(getPress(PRESS, image2));
                                        arg1.setVisibility(View.GONE);
break;
case 1:
PRESS[i] = WORD[position];
Grid_Game_Press.setAdapter(getPress(PRESS, image2));
break;
case 2:
PRESS[i] = WORD[position];
Grid_Game_Press.setAdapter(getPress(PRESS, image2));
break;
case 3:
PRESS[i] = WORD[position];
Grid_Game_Press.setAdapter(getPress(PRESS, image2));
break;
                                             ... ... ... 
                                             ... ... ... 
                                             ... ... ... 
case 23:
PRESS[i] = 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[i]);
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[i]);
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;
}


}

我来回答

所有回答
举报|(1)|(1)2014-02-21
隐藏可以用
xxx.setVisibility(View.INVISIBLE);
显示可以用
xxx.setVisibility(View.VISIBLE);
分别写在第一和第二的点击监听里。

举报|(1)|(1)2014-02-24
楼上正解
举报|(1)|(1)2014-04-08
隐藏可以用
xxx.setVisibility(View.INVISIBLE);
显示可以用
xxx.setVisibility(View.VISIBLE);
分别写在第一和第二的点击监听里。
举报|(1)|(1)2014-05-29
keyi
举报|(1)|(1)2014-07-05
xxx.setVisibility(View.INVISIBLE);
举报|(1)|(1)2014-07-07
没有懂,你到底想实现什么效果啊。
举报|(1)|(1)2014-12-11

看 不懂

举报|(1)|(1)2015-01-07
设置Visiable和Gone,每次重新刷新一次适配器
  • 回答:设置Visiable和Gone,每次重新刷新一次适配器
举报|(1)|(1)2017-04-18
??
举报|(1)|(1)2018-11-06
456
举报|(1)|(1)2019-05-25
E2W
举报|(1)|(1)2019-07-30
111

相关提问