title: Basic operations with UI components in Android
body: <p><strong>EDITED</strong>  </p>
  
  <p>I've created a simple UI in Android Studio which requires to use Button, Radio Group, Edit Text etc.</p>
  
  <ol>
  <li>So every time I press the radio button, it toasts the message which button was pressed.  </li>
  <li>If I type a specific word in search bar, in my example "Car", and the radio button is on Pictures, for example, the dialog box should pop up with the message "Pictures were found", or lets say I type in "Car" again and the radio button is checked on "Videos", then, in this case, the dialog box message will be "Videos were found".  </li>
  <li>If I press the search button, and the search field(EditText) is empty or have some other word(not "Car"), the dialog box's message should be "Unsuccessful search". So I could solve the first problem, my problem is with the Button and Search field, I can't find a way to link them to compare the user input with word "Car" and show the required dialog box.</li>
  </ol>
  
  <p>This is what it looks like</p>
  
  <p><a href="https://i.stack.imgur.com/jiSR2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jiSR2.png" alt="enter image description here"></a></p>
  
  <p>This is what I tried so far. 
  <strong>EDITED</strong></p>
  
  <pre><code> package com.example.administrator.simpleui;
  
  import android.content.DialogInterface;
  import android.support.v7.app.AlertDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.RadioButton;
  import android.widget.RadioGroup;
  import android.widget.Toast;
  
  public class MainActivity extends AppCompatActivity {
      RadioGroup radioGroup;
      RadioButton radioButton;
      Button button;
  
  //    EditText editText;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          radioGroup = (RadioGroup) findViewById(R.id.radio_group);
          final EditText editText = (EditText) findViewById(R.id.edit_text);
          button = (Button) findViewById(R.id.myButton);
          int radioId1 = radioGroup.getCheckedRadioButtonId();
          radioButton = (RadioButton) findViewById(radioId1);
  
          final AlertDialog.Builder alertDialog1 = new AlertDialog.Builder(this);
          alertDialog1.setTitle("Note").setMessage("Fail search").setPositiveButton("Ok", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                  Toast.makeText(getApplicationContext(),"Ok was pressed",Toast.LENGTH_SHORT).show();
              }
          }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                  Toast.makeText(getApplicationContext(),"Cancel was pressed",Toast.LENGTH_SHORT).show();
              }
          }).create();
  
          final AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(this);
          alertDialog2.setTitle("Note").setMessage(radioButton.getText() + " was found").setPositiveButton("ok", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                  Toast.makeText(getApplicationContext(),"ok was pressed",Toast.LENGTH_SHORT).show();
              }
          }).setNegativeButton("cancel", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                  Toast.makeText(getApplicationContext(),"ok was pressed",Toast.LENGTH_SHORT).show();
              }
          }).create();
  
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  if(editText.getEditableText().toString().equals("Car")) {
                      alertDialog2.show();
                  }else {
                      alertDialog1.show();
                  }
  
              }
          });
      }
  
      public void checkButton(View v){
          int radioId = radioGroup.getCheckedRadioButtonId();
          radioButton = (RadioButton) findViewById(radioId);
          Toast.makeText(this,  radioButton.getText() + " was selected",Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p>So i solved it by myself but still have one small bug,everytime i the Search for key word Car it the dialog box message shows me the value of radio button which i declared in my xml file(i have 4 radio buttons here, Videos,Pictures,Blog and FAQ and the one is checked by default is Videos) => so i always have the message like "Videos was found", but i need it show according the checked radio button, for example if the radio button is checked on Pictures and i typed in car then the the message is "Pictures was found", but my code only generates with videos. Problem is in this line: </p>
  
  <pre><code>final AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(this);
          alertDialog2.setTitle("Note").setMessage(radioButton.getText() + " was found").setPositiveButton("ok", new DialogInterface.OnClickListener()  
  </code></pre>
  
  <p>Don't know how to make it to see the current radio button. </p>