I required some assistance on the code, I manage to to create this the code for 5 button and one action, however i run on the phone it does when I clicked on the button.
Can some advise me why?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.android.testing1.MainActivity"
tools:showIn="@layout/activity_main">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="104dp"
android:layout_marginTop="20dp"
android:text="Button1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="100dp"
android:text="Button2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Button3" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="34dp"
android:text="Button4" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="24dp"
android:text="Button5" />
</RelativeLayout>
package com.example.android.testing1;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import static android.R.id.button1;
import static android.R.id.button2;
import static android.R.id.button3;
import static com.example.android.testing1.R.id.button4;
import static com.example.android.testing1.R.id.button5;
public class MainActivity extends AppCompatActivity {
Button b1, b2, b3, b4, b5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button dodo = (Button) findViewById(button1);
Button dede = (Button) findViewById(button2);
Button dada = (Button) findViewById(button3);
Button didi = (Button) findViewById(button4);
Button hehe = (Button) findViewById(button5);
return;
}
//boolean fafa, soso, raerae, gaga, gege;
public void main(Button args[]) {
final boolean fafa = true;
final boolean soso = true;
final boolean raerae = true;
final boolean gaga = true;
final boolean gege = true;
boolean returrn;
OnClickListener list = new OnClickListener() {
@Override
public void onClick(View v) {
if (fafa == true && soso == true && raerae == true && gaga == true && gege == true) {
Toast GetMeToast = Toast.makeText(MainActivity.this, "Open all buttons", Toast.LENGTH_SHORT);
GetMeToast.show();
}
}
};
}}
I tried to run the code above but was jammed once i clicked the button.
I am new to java. Required some assistance, what i need is that by clicking all the 5 buttons then the toast will appear.
I have tried many way it does not work. I think by creating a Boolean and if method can help me with this.
Aucun commentaire:
Enregistrer un commentaire