0

我在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;
                }
4

1 回答 1

0

你为什么不做:

  1. 公共静态 ArrayList imageResponded=new ArrayList(numberOfImages);
  2. 将 imageResponded arrayList 元素设置为 false
  3. 然后当用户选择一张图片时,您获取该图片的索引以了解在您的下一个活动中显示什么图片
  4. 当用户输入有关图像的正确答案时,您会看到
  5. 当您在网格视图活动中返回时,在 onResume 中,当您使用图像重新创建网格视图时,在将图像放入框中之前,您首先检查该索引上的 imageResponded.get(index) 是否返回 true,如果您设置图像的 alpha 为 75%,并在图像的右下方打勾
于 2013-10-15T13:06:29.970 回答