lundi 19 juin 2017

2 check boxes and Toast

I am new to android. My java code is not working when I want make a toast using the 2 check boxes.

Can some please help me.Let know if you do not understand my questions.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);



           final CheckBox Chk = (CheckBox) findViewById(R.id.checkBox);
            Boolean yeahdude = Chk.isChecked();
           final CheckBox Chs=(CheckBox) findViewById(R.id.checkBox2);
            Boolean yeahfriend = Chs.isChecked();
            if (yeahdude&yeahfriend) {


            Toast toast = Toast.makeText(this, "Fine Hi", Toast.LENGTH_SHORT);
            toast.show();

            return;
        }





<LinearLayout 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.testing3.MainActivity"
    tools:showIn="@layout/activity_main"
    android:orientation="vertical"
    >



    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox"
         />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox"
        />

</LinearLayout>

Let know if you do not understand my questions.




Aucun commentaire:

Enregistrer un commentaire