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;
}
}