0

So I have images in gridview. These images are shown in an activity. When one of the images is clicked, new activity is started with this image. In this activity, If user inputs correct answer, new activity is started that indicates the answer is correct. After user inputs correct answer, I want to set this image more transparent with a check mark in gridwiew. If the user clicks again to this correct view, I want to show same activity which indicates it was solved correct. How can I do that?

Here is my activity which contains grid view:

public class LogoSelectionActivity extends Activity {
.
.
 gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

             Intent intent = new Intent(LogoSelectionActivity.this, LogoActivity.class);
             intent.putExtra ("clicked_position", position);
             startActivity(intent);
}

Here is my activity where user enter inputs:

public class LogoActivity extends Activity{

EditText text;
Button check;
Boolean a;
int id;
Names name;
@Override

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_logo);
    check = (Button) findViewById(R.id.Check_button);
    text = (EditText) findViewById(R.id.editText1);
    ImageView view = (ImageView)findViewById(R.id.imageView1);
    final ImageView incorrect = (ImageView)findViewById(R.id.incorrect);
    switch (getIntent().getIntExtra ("clicked_position", -1))
    {
      case 0:
        view.setImageResource(R.drawable.adese);
        id = R.drawable.adese;
        break;
      case 1:
         view.setImageResource(R.drawable.birvar);
         id = R.drawable.birvar;
         break;
      case 2:
         view.setImageResource(R.drawable.agaoglu);
         break;
      case 3:
          view.setImageResource(R.drawable.akinsoft);
          break;
      default:
         view.setImageResource(R.drawable.afra);
         id = R.drawable.afra;
    }
    name = Names.forDrawable(id);
    check.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            a=name.isCorrect(text.getText().toString());
            if(a==true){
            Intent intent = new Intent(LogoActivity.this, CorrectActivity.class);
            startActivity(intent);
            }
            else{
                incorrect.setVisibility(0);
                incorrect.setVisibility(4);
            }
        }
        });
    }
}

I hope I could explain my intention clearly.

4

1 回答 1

1

有很多方法可以做到这一点。因为这不是问题,所以这是您在项目中想要的功能。

根据我的逻辑,我给你一个解决方案。

脚步:

  1. 在网格视图中创建一个静态数组,其项目长度为默认值为 0。

     static int[] items = {0,0,0,...};
    
  2. 现在getView根据数组中的位置使用值检查网格视图的方法,如果它是 0,那么它看起来像正常,否则它看起来会不同(这里你想要透明的复选框,你可以通过在上面添加一个图像来获得它。)

    If(items[position] == 0){
    
    }else{
    
    }
    
  3. 现在,当用户点击任何图像并导航到其他屏幕(假设活动 B)时,该时间从该数组传递该位置的值并检查活动 B 的OnCreate()

    gridview.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    
         Intent intent = new Intent(LogoSelectionActivity.this, LogoActivity.class);
         intent.putExtra ("clicked_position", position);
         intent.putExtra ("answered_or_not", items[position]);
    
         startActivity(intent);
    }
    
  4. 如果回答意味着它的值是否为 1,则相应地显示其他情况。

  5. 当用户给出答案未回答的问题时,在该数组中将其值设为 1。

我希望它会帮助你,如果有任何问题。

于 2013-03-03T12:36:03.237 回答