условие IF для двух кнопок
Добавлено: 02 фев 2014, 14:01
Нужно чтобы при нажатии двух верных кнопок менялась картинка, как реализовать?
Есть 3 кнопки и есть еще 4-я кнопка, которая должна меняться при 2-х верных вариантах.
Короче: Как реализовать логику выбора двух и более правильных вариантов, если все правильные выбраны,то что-то делать
Активити:
xml:
Есть 3 кнопки и есть еще 4-я кнопка, которая должна меняться при 2-х верных вариантах.
Короче: Как реализовать логику выбора двух и более правильных вариантов, если все правильные выбраны,то что-то делать
Активити:
Код: Выделить всё
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends Activity {
ImageButton imageButton1;
ImageButton imageButton2;
ImageButton imageButton3;
ImageButton imageButton4;
boolean b1isRight = false;
boolean b2isRight = false;
boolean b3isRight = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageButton1 = (ImageButton)findViewById(R.id.imageButton1);
imageButton2 = (ImageButton)findViewById(R.id.imageButton2);
imageButton3 = (ImageButton)findViewById(R.id.imageButton3);
imageButton4 = (ImageButton)findViewById(R.id.imageButton4);
}
public void onClickStartl(View v) {
b1isRight = true;
}
public void onClickStart2(View v) {
}
public void onClickStart3(View v) {
b3isRight = true;
}
{
if (b1isRight && b3isRight){
imageButton4.setBackgroundResource(R.drawable.zik);
}
}
}
Код: Выделить всё
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="44dp"
android:layout_toLeftOf="@+id/imageButton2"
android:onClick="onClickStartl"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="onClickStart2"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageButton2"
android:layout_marginLeft="50dp"
android:layout_toRightOf="@+id/imageButton2"
android:onClick="onClickStart3"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginRight="22dp"
android:src="@drawable/ic_launcher" />
</RelativeLayout>