Soru & Cevap

Buton Renklendirme ...

08.04.2016 - 09:02

Merhabalar;

Çoktan seçmeli bir test uygulaması yapmaya çalışmaktayım. Java ve android hakkında bilgim yok sayılır. Şuana kadar Ana menüyü ve çoktan seçmeli test ekranı menüsünü ve ana menüden çoktan seçmeli test ekranına geçişi başarabildim. Şimdi yapmak istediğim ise kullanıcı cevap şıklarına dokunduğunda dokunulan butonun kırmızı renge dönüşmesi. Ancak bunu yaparken cevabı değiştirmek istediğinde diğer butona bastığında ilk butonun rengi kırmızıdan öncekine dönmeli ve yeni seçim kırmızı olmalı. 

A butonu id: button3

B butonu id: button4

C butonu id: button5

D butonu id: button6

E butonu id: button7

başka bir bilgi gerekiyo mu bilmiyorum :( 

Anlatmaya çalıştığımı başarabilmek için nerelere hangi kodları yazmam gerekiyor?

 

 

85 Görüntülenme

2 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user paracetamooll
paracetamooll
11.04.2016 - 09:39

Sayın Emre Taşbaş; 

Verdiğiniz kodlarla uğraşmama rağmen başaramadım. Mutlaka benim eksikliğim. Daha basit bir yöntremi olduğuna min olmakla birlikte o yolu bulamadım ama işimin çözümünü de bulmuş bulunmaktayım. Lazım olan arkadaşlar olur diye kendi çözümümü payhlaşıyorum.

import com.google.android.gms.common.api.GoogleApiClient;


public class Tarihekrani extends Activity {

    TextView tv1;
    Button btn3, btn4, btn5, btn6, btn7, btn8, btn9;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tarih_ekrani);

        tv1 = (TextView) findViewById(R.id.textView);
        btn3 = (Button) findViewById(R.id.button3);
        btn4 = (Button) findViewById(R.id.button4);
        btn5 = (Button) findViewById(R.id.button5);
        btn6 = (Button) findViewById(R.id.button6);
        btn7 = (Button) findViewById(R.id.button7);
        btn8 = (Button) findViewById(R.id.button8);
        btn9 = (Button) findViewById(R.id.button9);

        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn4.getBackground().clearColorFilter();
                btn5.getBackground().clearColorFilter();
                btn6.getBackground().clearColorFilter();
                btn7.getBackground().clearColorFilter();
                btn3.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
                Toast.makeText(Tarihekrani.this, "A Şıkkını İşaretlediniz!", Toast.LENGTH_SHORT).show();
            }
        });
        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn3.getBackground().clearColorFilter();
                btn5.getBackground().clearColorFilter();
                btn6.getBackground().clearColorFilter();
                btn7.getBackground().clearColorFilter();
                btn4.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
                Toast.makeText(Tarihekrani.this, "B Şıkkını İşaretlediniz!", Toast.LENGTH_SHORT).show();
            }
        });
        btn5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn3.getBackground().clearColorFilter();
                btn4.getBackground().clearColorFilter();
                btn6.getBackground().clearColorFilter();
                btn7.getBackground().clearColorFilter();
                btn5.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
                Toast.makeText(Tarihekrani.this, "C Şıkkını İşaretlediniz!", Toast.LENGTH_SHORT).show();
            }
        });
        btn6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn3.getBackground().clearColorFilter();
                btn4.getBackground().clearColorFilter();
                btn5.getBackground().clearColorFilter();
                btn7.getBackground().clearColorFilter();
                btn6.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
                Toast.makeText(Tarihekrani.this, "D Şıkkını İşaretlediniz!", Toast.LENGTH_SHORT).show();
            }
        });
        btn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn3.getBackground().clearColorFilter();
                btn4.getBackground().clearColorFilter();
                btn5.getBackground().clearColorFilter();
                btn6.getBackground().clearColorFilter();
                btn7.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
                Toast.makeText(Tarihekrani.this, "E Şıkkını İşaretlediniz!", Toast.LENGTH_SHORT).show();
            }

        });
       







        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }


    @Override
    public void onStart() {
        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client.connect();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "Tarihekrani Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
                Uri.parse("android-app://com.example.recep.kpss2/http/host/path")
        );
        AppIndex.AppIndexApi.start(client, viewAction);
    }

    @Override
    public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "Tarihekrani Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
                Uri.parse("android-app://com.example.recep.kpss2/http/host/path")
        );
        AppIndex.AppIndexApi.end(client, viewAction);
        client.disconnect();
    }
}

 

picture-62423-1460561213.jpg
emre.tsbs
08.04.2016 - 10:31

Merhaba, soru cevap tarzı çoktan seçmeli durumlarda radiobutton tavsiyemdir. Sizin için birşeyler yazdım şimdi taslak olarak kullanabilirsiniz.

Soru1.class

package com.example.envy_m6.sorucevap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by envy-m6 on 8.4.2016.
 */
public class Soru1 extends Activity {

    TextView tv1;
    RadioGroup rg1;
    RadioButton rb1, rb2, rb3, rb4, rb5;
    Button btn1, btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.soru1);

        tv1 = (TextView)findViewById(R.id.textView);
        rg1 = (RadioGroup)findViewById(R.id.radioGroup);
        rb1 = (RadioButton)findViewById(R.id.radioButton);
        rb2 = (RadioButton)findViewById(R.id.radioButton2);
        rb3 = (RadioButton)findViewById(R.id.radioButton3);
        rb4 = (RadioButton)findViewById(R.id.radioButton4);
        rb5 = (RadioButton)findViewById(R.id.radioButton5);
        btn1 = (Button)findViewById(R.id.button);
        btn2 = (Button)findViewById(R.id.button2);

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (rb1.isChecked()) {
                    Toast.makeText(getApplicationContext(), "Yanlış Cevap!", Toast.LENGTH_SHORT).show();
                    Intent i = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(i);
                } else if (rb2.isChecked()) {
                    Toast.makeText(getApplicationContext(), "Yanlış Cevap!", Toast.LENGTH_SHORT).show();
                    Intent i = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(i);
                } else if (rb3.isChecked()) {
                    Toast.makeText(getApplicationContext(), "Doğru Cevap, tebrikler.", Toast.LENGTH_SHORT).show();
                    Intent i = new Intent(getApplicationContext(), Soru2.class);
                    startActivity(i);
                } else if (rb4.isChecked()) {
                    Toast.makeText(getApplicationContext(), "Yanlış Cevap!", Toast.LENGTH_SHORT).show();
                    Intent i = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(i);
                } else if (rb5.isChecked()) {
                    Toast.makeText(getApplicationContext(), "Yanlış Cevap!", Toast.LENGTH_SHORT).show();
                    Intent i = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(i);
                } else {
                    Toast.makeText(getApplicationContext(), "Seçim Yapmadınız!", Toast.LENGTH_SHORT).show();
                }
            }
        });

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.exit(0);
                finish();
            }
        });
    }
}

Doğru cevabı radiobuttonlar içine kendiniz gizlemelisiniz. Buradaki doğru cevap 3. şık gibi. Ayrıca doğru cevabı verince Soru2.class'a geçiş yapıyor. Her class için yeniden oluşturulup birbirine bağlanması gerekir.

Her yanlış cevapta ise anasayfaya yönlenip kullanıcının tekrar başlaması sağlanıyor.

soru1.xml

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="120dp">

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Soru 1: abcdef"
            android:id="@+id/textView" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="250dp">

        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/radioGroup">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Cevap 1"
                android:id="@+id/radioButton"
                android:checked="false" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Cevap 2"
                android:id="@+id/radioButton2"
                android:checked="false" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Cevap 3"
                android:id="@+id/radioButton3"
                android:checked="false" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Cevap 4"
                android:id="@+id/radioButton4"
                android:checked="false" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Cevap 5"
                android:id="@+id/radioButton5"
                android:checked="false" />
        </RadioGroup>
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Geri"
            android:id="@+id/button" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cevapla"
            android:id="@+id/button2"
            android:layout_marginLeft="100dp" />
    </LinearLayout>
</LinearLayout>

Ben böyle birşey düzenledim ama üzerine dilediğiniz gibi görsellik katabilirsiniz.

Son olarak AndroidManifest.xml dosyasına her açılan activity için bir activity bloğu eklenmeli.

<activity android:name=".Soru1" >
            <intent-filter>
                <action android:name="android.intent.action.SORU1" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>