关于正确或错误的答案

时间:2017-01-31 19:35:45

标签: android android-studio

我想要一个3-4岁孩子的测试。我想如果他们点击不同的苹果,真正的数量必须加一。如果他们点击相同的aplles之一,则假计数必须加1。然后点击任何苹果问题和苹果必须改变。

我的朋友帮了我,我们做了很多。点击问题和答案的变化。但是当点击任何苹果错误计数加上一个时,无论它是真是假答案。

你能帮助我吗?

我们认为if命令只会出现问题。他试了很多但却无法解决问题。

类文件:

package tr.com.blogspot.etkinlikhavuzu.benimilkogretmenim;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Random;

/**
 * Created by erisk on 31.01.2017.
 */

public class AA extends Activity implements View.OnClickListener{

    TextView soru,dogrusayi,yanlissayi;
    ImageView secenek1,secenek2,secenek3;
    ArrayList<Soru> sorular;
    Random random;
    int dogruSayisi,yanlisSayisi,sayac,dogruCevap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.aa);

        init();

        sorulariYukle();
    }

    public void init(){
        secenek1 = (ImageView) findViewById(R.id.secenek1);
        secenek1.setOnClickListener(this);
        secenek2 = (ImageView) findViewById(R.id.secenek2);
        secenek2.setOnClickListener(this);
        secenek3 = (ImageView) findViewById(R.id.secenek3);
        secenek3.setOnClickListener(this);

        soru = (TextView) findViewById(R.id.soru);
        dogrusayi = (TextView) findViewById(R.id.dogrusayi);
        yanlissayi = (TextView) findViewById(R.id.yanlissayi);

        sorular = new ArrayList<Soru>();

        random = new Random();
    }

    public void sorulariYukle(){
        sorular.add(new Soru("Hangi Elma Yeşildir?",R.drawable.yesilelma,R.drawable.kirmizielma,R.drawable.kirmizielma,R.drawable.yesilelma));
        sorular.add(new Soru("Hangi Elma Kırmızıdır?",R.drawable.kirmizielma,R.drawable.yesilelma,R.drawable.yesilelma,R.drawable.kirmizielma));
        sorular.add(new Soru("Hangi Elma Yeşildir?",R.drawable.kirmizielma,R.drawable.yesilelma,R.drawable.kirmizielma,R.drawable.yesilelma));
        sorular.add(new Soru("Hangi Elma Kırmızıdır?",R.drawable.yesilelma,R.drawable.yesilelma,R.drawable.kirmizielma,R.drawable.kirmizielma));
        sorular.add(new Soru("Hangi Elma Yeşildir?",R.drawable.kirmizielma,R.drawable.kirmizielma,R.drawable.yesilelma,R.drawable.yesilelma));

        sayac = random.nextInt(5);

        soru.setText(sorular.get(sayac).getSoru());
        secenek1.setImageResource(sorular.get(sayac).getSecenek1());
        secenek2.setImageResource(sorular.get(sayac).getSecenek2());
        secenek3.setImageResource(sorular.get(sayac).getSecenek3());
        dogruCevap = sorular.get(sayac).getDogruCevap();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.secenek1:
                if(secenek1.getDrawable() == getResources().getDrawable(dogruCevap)){
                    dogruSayisi++;
                    dogrusayi.setText(String.valueOf(dogruSayisi));
                }else{
                    yanlisSayisi++;
                    yanlissayi.setText(String.valueOf(yanlisSayisi));
                }
                sayac = random.nextInt(5);
                soru.setText(sorular.get(sayac).getSoru());
                secenek1.setImageResource(sorular.get(sayac).getSecenek1());
                secenek2.setImageResource(sorular.get(sayac).getSecenek2());
                secenek3.setImageResource(sorular.get(sayac).getSecenek3());
                dogruCevap = sorular.get(sayac).getDogruCevap();
                break;
            case R.id.secenek2:
                if(secenek2.getDrawable() == getResources().getDrawable(dogruCevap)){
                    dogruSayisi++;
                    dogrusayi.setText(String.valueOf(dogruSayisi));
                }else{
                    yanlisSayisi++;
                    yanlissayi.setText(String.valueOf(yanlisSayisi));
                }
                sayac = random.nextInt(5);
                soru.setText(sorular.get(sayac).getSoru());
                secenek1.setImageResource(sorular.get(sayac).getSecenek1());
                secenek2.setImageResource(sorular.get(sayac).getSecenek2());
                secenek3.setImageResource(sorular.get(sayac).getSecenek3());
                dogruCevap = sorular.get(sayac).getDogruCevap();
                break;
            case R.id.secenek3:
                if(secenek3.getDrawable() == getResources().getDrawable(dogruCevap)){
                    dogruSayisi++;
                    dogrusayi.setText(String.valueOf(dogruSayisi));
                }else{
                    yanlisSayisi++;
                    yanlissayi.setText(String.valueOf(yanlisSayisi));
                }
                sayac = random.nextInt(5);
                soru.setText(sorular.get(sayac).getSoru());
                secenek1.setImageResource(sorular.get(sayac).getSecenek1());
                secenek2.setImageResource(sorular.get(sayac).getSecenek2());
                secenek3.setImageResource(sorular.get(sayac).getSecenek3());
                dogruCevap = sorular.get(sayac).getDogruCevap();
                break;
        }
    }
}

xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="tr.com.blogspot.etkinlikhavuzu.benimilkogretmenim.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="30dp">

        <Button
            android:id="@+id/dogru"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:background="@drawable/dogru" />

        <Button
            android:id="@+id/yanlis"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/dogru"
            android:layout_marginTop="10dp"
            android:background="@drawable/yanlis" />

        <TextView
            android:id="@+id/dogrusayi"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_above="@+id/yanlis"
            android:layout_toEndOf="@+id/dogru"
            android:layout_toRightOf="@+id/dogru"
            android:gravity="center"
            android:text="@string/dogrusayi"
            android:textColor="#006600"
            android:textSize="30sp" />

        <TextView
            android:id="@+id/yanlissayi"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_alignBottom="@+id/yanlis"
            android:layout_toEndOf="@+id/yanlis"
            android:layout_toRightOf="@+id/yanlis"
            android:gravity="center"
            android:text="@string/yanlissayi"
            android:textColor="#990000"
            android:textSize="30sp" />
        <ImageView
            android:id="@+id/secenek1"
            android:layout_width="170dp"
            android:layout_height="170dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
        <ImageView
            android:id="@+id/secenek2"
            android:layout_width="170dp"
            android:layout_height="170dp"
            android:layout_alignBottom="@+id/secenek1"
            android:layout_centerHorizontal="true" />
        <ImageView
            android:id="@+id/secenek3"
            android:layout_width="170dp"
            android:layout_height="170dp"
            android:layout_alignBottom="@+id/secenek2"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true" />

        <TextView
            android:id="@+id/soru"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/secenek2"
            android:layout_marginBottom="18dp"
            android:layout_toEndOf="@+id/dogrusayi"
            android:layout_toRightOf="@+id/dogrusayi"
            android:gravity="center"
            android:text="Hangi Elma Yeşildir?"
            android:textColor="#006600"
            android:textSize="40sp"
            android:textStyle="bold|italic" />

        <TextView
            android:id="@+id/siradaki"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:textColor="#000000" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="1" />



    </RelativeLayout>
</RelativeLayout>

和Soru.class文件

package tr.com.blogspot.etkinlikhavuzu.benimilkogretmenim;

/**
 * Created by erisk on 31.01.2017.
 */

public class Soru {
    String soru;
    int secenek1,secenek2,secenek3,dogruCevap;

    public Soru(String soru, int secenek1, int secenek2, int secenek3, int dogruCevap) {
        this.soru = soru;
        this.secenek1 = secenek1;
        this.secenek2 = secenek2;
        this.secenek3 = secenek3;
        this.dogruCevap = dogruCevap;
    }

    public String getSoru() {
        return soru;
    }

    public void setSoru(String soru) {
        this.soru = soru;
    }

    public int getSecenek1() {
        return secenek1;
    }

    public void setSecenek1(int secenek1) {
        this.secenek1 = secenek1;
    }

    public int getSecenek2() {
        return secenek2;
    }

    public void setSecenek2(int secenek2) {
        this.secenek2 = secenek2;
    }

    public int getSecenek3() {
        return secenek3;
    }

    public void setSecenek3(int secenek3) {
        this.secenek3 = secenek3;
    }

    public int getDogruCevap() {
        return dogruCevap;
    }

    public void setDogruCevap(int dogruCevap) {
        this.dogruCevap = dogruCevap;
    }
}

非常感谢

1 个答案:

答案 0 :(得分:0)

您正在比较drawables。从不匹配。 将你的if(CONDITION)改为以下:

if(secenek1.getDrawable().getConstantState().equals(getResources().getDrawable(dogruCevap).getConstantState())).

其他两种情况相同。