title: Android studio Hide and Show buttons from a condition
body: <p>my android app needs a function that has a button that needs to show and hide based on one <code>TextView</code>. Here is my code and ill explain further.</p>
  <pre><code>public class currentCar extends Fragment implements AsyncResponse, AdapterView.OnItemClickListener {
  final String TAG = this.getClass().getName();
  private ArrayList&lt;AcceptCars&gt; carList;
  private ListView lvCurrent;
  private FunDapter&lt;AcceptCars&gt; adapter;
  SharedPreferences pref;
  
  public currentCar() {
      // Required empty public constructor
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View v =  inflater.inflate(R.layout.fragment_current_car, container, false);
  
      ImageLoader.getInstance().init(UILConfig.config(getActivity()));
  
      lvCurrent = (ListView) v.findViewById(R.id.lvCurrent);
  
      pref = getActivity().getSharedPreferences(&quot;Login.conf&quot;, Context.MODE_PRIVATE);
      Log.d(TAG, pref.getString(&quot;username&quot;,&quot;&quot;));
  
      PostResponseAsyncTask taskRead = new PostResponseAsyncTask(getActivity(), this);
  
      taskRead.execute(&quot;http://carkila.esy.es/carkila/current.php?acceptCarOwner=&quot;+pref.getString(&quot;username&quot;,&quot;&quot;));
  
      return v;
  }
  
  @Override
  public void processFinish(String s) {
      carList = new JsonConverter&lt;AcceptCars&gt;().toArrayList(s, AcceptCars.class);
  
      BindDictionary&lt;AcceptCars&gt; dict = new BindDictionary&lt;AcceptCars&gt;();
  
      dict.addDynamicImageField(R.id.ivImg1, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return item.acceptImage;
          }
      }, new DynamicImageLoader() {
          @Override
          public void loadImage(String url, ImageView view) {
  
              ImageLoader.getInstance().displayImage(url, view);
          }
      });
      dict.addStringField(R.id.tvCarModel, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Car Model: &quot; + item.acceptModel;
          }
      });
      dict.addStringField(R.id.tvResDate, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Date: &quot; + item.acceptDate;
          }
      });
      dict.addStringField(R.id.tvResTime, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Time: &quot; + item.acceptTime;
          }
      });
      dict.addStringField(R.id.tvResLocation, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Location: &quot; + item.acceptResLocation;
          }
      });
      dict.addStringField(R.id.tvCarType, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Car Type: &quot; + item.acceptType;
          }
      });
      dict.addStringField(R.id.tvCapacity, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Capacity: &quot; + item.acceptCapacity;
          }
      });
      dict.addStringField(R.id.tvFuelType, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Fuel Type: &quot; + item.acceptFuelType;
          }
      });
      dict.addStringField(R.id.tvPlateNumber, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Plate Number: &quot; + item.acceptPlateNumber;
          }
      });
      dict.addStringField(R.id.tvPoster, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Posted by : &quot; + item.acceptCarOwner;
          }
      });
      dict.addStringField(R.id.tvRenter, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Rented by: &quot;+ item.renters;
          }
      });
      dict.addStringField(R.id.tvDestination, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Destination: &quot; + item.acceptDestination;
          }
      });
  
      dict.addStringField(R.id.tvResPrice, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Destination: &quot; + item.acceptPrice;
          }
      });
      dict.addStringField(R.id.tvresID, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;&quot;+ item.acceptedID;
          }
      });
      dict.addStringField(R.id.tvstatus, new StringExtractor&lt;AcceptCars&gt;() {
          @Override
          public String getStringValue(AcceptCars item, int position) {
              return &quot;Status: &quot;+ item.payment;
          }
      });
  
      adapter = new FunDapter&lt;&gt;(
              getActivity(), carList, R.layout.layout_rented, dict);
      lvCurrent.setAdapter(adapter);
      lvCurrent.setOnItemClickListener(this);
  }
  
  @Override
  public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
      AcceptCars selectedCars = carList.get(i);
          Intent in = new Intent(getActivity(), ownerStatus.class);
          in.putExtra(&quot;cars&quot;, selectedCars);
          startActivity(in);
  }
  }
  </code></pre>
  <p>On the start of this <code>listView</code> the <code>item.payment</code> is &quot;unpaid&quot; and it will go to <code>ownerStatus.class</code></p>
  <h1>OwnerStatus.class</h1>
  <pre><code>public class ownerStatus extends AppCompatActivity {
  TextView tvStatus, tvPaymentStatus, tvresID, tvCarModel, tvCarType, tvCapacity, tvFuelType, tvPlateNumber, tvResDate, tvResTime, tvResLocation, tvPoster, tvRenter, tvDestination, tvPrice;
  ImageView ivImage;
  Button btnPaid;
  Button btnDone;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_owner_status);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      onButtonClick();
  
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      final AcceptCars Cars = (AcceptCars) getIntent().getSerializableExtra(&quot;cars&quot;);
      ImageLoader.getInstance().init(UILConfig.config(ownerStatus.this));
      tvCarModel = (TextView) findViewById(R.id.tvCarModel);
      tvCarType = (TextView) findViewById(R.id.tvCarType);
      tvCapacity = (TextView) findViewById(R.id.tvCapacity);
      tvFuelType = (TextView) findViewById(R.id.tvFuelType);
      tvPoster = (TextView) findViewById(R.id.tvPoster);
      tvPlateNumber = (TextView) findViewById(R.id.tvPlateNumber);
      tvResDate = (TextView) findViewById(R.id.tvResDate);
      tvResTime = (TextView) findViewById(R.id.tvResTime);
      tvResLocation = (TextView) findViewById(R.id.tvResLocation);
      tvPrice = (TextView) findViewById(R.id.tvPrice);
      tvDestination = (TextView) findViewById(R.id.tvDestination);
      tvRenter = (TextView) findViewById(R.id.tvRenter);
      tvresID = (TextView) findViewById(R.id.tvresID);
      tvPaymentStatus = (TextView) findViewById(R.id.tvPaymentStatus);
      tvStatus = (TextView) findViewById(R.id.tvStatus);
      ivImage = (ImageView) findViewById(R.id.ivImg1);
  
      if (Cars != null) {
          tvresID.setText(&quot;&quot; + Cars.acceptedID);
          tvCarModel.setText(Cars.acceptModel);
          tvCarType.setText(Cars.acceptType);
          tvCapacity.setText(Cars.acceptCapacity);
          tvFuelType.setText(Cars.acceptFuelType);
          tvPlateNumber.setText(Cars.acceptPlateNumber);
          tvResDate.setText(Cars.acceptDate);
          tvResTime.setText(Cars.acceptTime);
          tvResLocation.setText(Cars.acceptResLocation);
          tvPoster.setText(Cars.acceptCarOwner);
          tvRenter.setText(Cars.renters);
          tvDestination.setText(Cars.acceptDestination);
          tvPrice.setText(Cars.acceptPrice);
          tvPaymentStatus.setText(Cars.payment);
          tvStatus.setText(Cars.payment);
  
          ImageLoader.getInstance().displayImage(Cars.acceptImage, ivImage);
      }
  
  }
  
  public void onButtonClick() {
      btnPaid = (Button) findViewById(R.id.btnPaid);
      btnPaid.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              AlertDialog.Builder a_paid = new AlertDialog.Builder(ownerStatus.this);
              a_paid.setMessage(&quot;Does the renter paid the transaction?&quot;)
                      .setCancelable(false)
                      .setPositiveButton(&quot;Yes&quot;, new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialogInterface, int i) {
                              HashMap postData = new HashMap();
                              postData.put(&quot;acceptID&quot;, tvresID.getText().toString());
                              postData.put(&quot;payment&quot;, &quot;paid&quot;);
                              PostResponseAsyncTask taskPaid = new PostResponseAsyncTask(ownerStatus.this, postData, false, new AsyncResponse() {
                                  @Override
                                  public void processFinish(String s) {
                                      if (s.contains(&quot;success&quot;)) {
                                          Toast.makeText(ownerStatus.this, &quot;renter is paid&quot;, Toast.LENGTH_SHORT).show();
                                          Intent in = new Intent(ownerStatus.this, OwnerTabs.class);
                                          startActivity(in);
                                          finish();
                                      } else {
                                          Toast.makeText(getApplicationContext(), &quot;Failed. Zzzz ☻&quot;, Toast.LENGTH_LONG).show();
                                      }
                                  }
                              });
                              taskPaid.execute(&quot;http://carkila.esy.es/carkila/paid.php&quot;);
                          }
                      })
                      .setNegativeButton(&quot;No&quot;, new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialogInterface, int i) {
                              dialogInterface.cancel();
                          }
                      });
              AlertDialog alert = a_paid.create();
              alert.setTitle(&quot;Payment&quot;);
              alert.show();
          }
      });
      //===================================================================================//
      btnDone = (Button) findViewById(R.id.btnDone);
      btnDone.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              AlertDialog.Builder a_done = new AlertDialog.Builder(ownerStatus.this);
              a_done.setMessage(&quot;Is the rent is done?&quot;)
                      .setCancelable(false)
                      .setPositiveButton(&quot;Yes&quot;, new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialogInterface, int i) {
                              HashMap postData2 = new HashMap();
                              postData2.put(&quot;acceptID&quot;, tvresID.getText().toString());
                              postData2.put(&quot;status&quot;, &quot;done&quot;);
                              PostResponseAsyncTask task1 = new PostResponseAsyncTask(ownerStatus.this, postData2, new AsyncResponse() {
                                  @Override
                                  public void processFinish(String s) {
                                      if (s.contains(&quot;success&quot;)) {
                                          Toast.makeText(ownerStatus.this, &quot;renter is paid&quot;, Toast.LENGTH_SHORT).show();
                                      } else {
                                          Toast.makeText(getApplicationContext(), &quot;Failed. Zzzz ☻&quot;, Toast.LENGTH_LONG).show();
                                      }
                                  }
                              });
                              task1.execute(&quot;http://carkila.esy.es/carkila/done.php&quot;);
                                  }
                              })
                      .setNegativeButton(&quot;No&quot;, new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialogInterface, int i) {
                              dialogInterface.cancel();
                          }
                      });
              AlertDialog alert = a_done.create();
              alert.setTitle(&quot;Done&quot;);
              alert.show();
          }
      });
  }
  }
  </code></pre>
  <p>And on here. When the <code>Cars.payment</code> is unpaid the <code>btnPaid</code> will show and hide the <code>btnDone</code> but when the <code>Cars.payment</code> is paid the <code>btnPaid</code> will hide and the <code>btnDone</code> will now Hide.
  Hope you understand how i explained and help me with my problem. Thanks sir :)</p>