我在gridview中有图像。这些图像显示在一个活动中。单击其中一个图像时,将使用该图像启动新活动。在这个活动中,如果用户输入正确的答案,则启动新的活动,表明答案是正确的。用户输入正确答案后,我想在 gridwiw 中使用复选标记将此图像设置为更透明。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level1);
initComponent();
gva.setAdapter(new ImageAdaptera(getApplicationContext()));
gva.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
switch (position) {
case 0:
{
Intent intenta = new Intent (getBaseContext(), AA.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intenta,0);
}
break;
case 1:
{
Intent intentb = new Intent (getBaseContext(), AB.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intentb,0);
}
break;
case 2:
{
Intent intentc = new Intent (getBaseContext(), AC.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intentc,0);
}
break;
}}
}
我的图像适配器:
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageViewa;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageViewa = new ImageView(mContext);
imageViewa.setLayoutParams(new GridView.LayoutParams(85, 85));
imageViewa.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageViewa.setPadding(8, 8, 8, 8);
} else {
imageViewa = (ImageView) convertView;
}
imageViewa.setImageResource(imagesa[position]);
return imageViewa;
}
儿童活动:
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
String check = input.getText().toString().replace(" ","");
Editor editor = mGameSettings.edit();
editor.putString(GAME_PREFERENCES_answeraa, check);
editor.commit();
if(check.equalsIgnoreCase("petronet")){
display.setText("correct");
Toast.makeText(AA.this,"CORRECT",Toast.LENGTH_SHORT).show();
Intent data = new Intent();
// TODO Add extras or a data URI to this intent as appropriate.
setResult(RESULT_OK, data);
input.setEnabled(false);Guruapp.levela++;Guruapp.count++;
int hc2 = mGameSettings.getInt(GAME_PREFERENCES_hint, Guruapp.count);
Guruapp.count = hc2;
finish();
}
else{
display.setText("Wrong");
Toast.makeText(AA.this,"WRONG",Toast.LENGTH_SHORT).show();
return false;
}