imageView with button name change such as when image select A, Other hand show A button name and other 3 button has b,c,d. Its all have to Randomly .. One button have true other three are wrong. how i can do? i do imageView randomly selected but not adjust other. i do imageView randomly selected but not adjust other.
res/layout/activity_letter_test_first
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
xmlns:tools="http://ift.tt/LrGmb4"
android:id="@+id/activity_letter_test_first"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.nayemuzzaman.learning.LetterTestFirst">
<TextView
android:text="Try to find A "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/a"
android:id="@+id/imgViewRandom"
android:onClick="imageLetterRandom" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Button"
android:layout_width="182dp"
android:layout_height="wrap_content"
android:id="@+id/button" />
<Button
android:text="Button"
android:layout_width="171dp"
android:layout_height="wrap_content"
android:id="@+id/button4" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="59dp">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button5"
android:layout_weight="1.14" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button6"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
java/com.example.nayemuzzaman.learning/LetterTestFirst
package com.example.nayemuzzaman.learning;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import java.util.Random;
public class LetterTestFirst extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_letter_test_first);
final int[] phtLetter={R.drawable.a, R.drawable.b, R.drawable.c}; //total picture add
final ImageView imgViewRnd=(ImageView) findViewById(R.id.imgViewRandom); //imageView address
final Random ranLtr=new Random();
int imgLetter=ranLtr.nextInt(phtLetter.length);
imgViewRnd.setImageResource(phtLetter[imgLetter]);
imgViewRnd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int tlLetter = ranLtr.nextInt(phtLetter.length); //total length letter photos & random selected photos.
imgViewRnd.setImageResource(phtLetter[tlLetter]);
}
});
}
}
Aucun commentaire:
Enregistrer un commentaire