0

I have ten image view in my app that their visibility is set to invisible in XMl. I wrote if condition in java to visibility them programmatically but I don't know why they still are invisible.

    EditText b = (EditText) findViewById(R.id.edit_b_beam);
    EditText h = (EditText) findViewById(R.id.edit_h_beam);
    EditText fc = (EditText) findViewById(R.id.edit_fc_beam);
    EditText fy = (EditText) findViewById(R.id.edit_fy_beam);
    EditText ffy = (EditText) findViewById(R.id.edit_ffy_beam);
    EditText nAs = (EditText) findViewById(R.id.edit_nAs_beam);
    EditText ds = (EditText) findViewById(R.id.edit_ds_beam);
    EditText nAAs = (EditText) findViewById(R.id.edit_nAAs_beam);
    EditText dds = (EditText) findViewById(R.id.edit_dds_beam);
    EditText cover = (EditText) findViewById(R.id.edit_cover_beam);


    ImageView image_b=(ImageView) findViewById(R.id.image_b);
    ImageView image_h=(ImageView) findViewById(R.id.image_h);
    ImageView image_fc=(ImageView) findViewById(R.id.image_fc);
    ImageView image_fy=(ImageView) findViewById(R.id.image_fy);
    ImageView image_nAs=(ImageView) findViewById(R.id.image_nAs);
    ImageView image_ds=(ImageView) findViewById(R.id.image_ds);
    ImageView image_cover=(ImageView) findViewById(R.id.image_cover);
    ImageView image_ffy=(ImageView) findViewById(R.id.image_ffy);
    ImageView image_nAAs=(ImageView) findViewById(R.id.image_nAAs);
    ImageView image_dds=(ImageView) findViewById(R.id.image_dds);

    if(!b.getText().toString().isEmpty())
        image_b.setVisibility(View.VISIBLE);
    if(!h.getText().toString().isEmpty())
        image_h.setVisibility(View.VISIBLE);
    if(!fc.getText().toString().isEmpty())
        image_fc.setVisibility(View.VISIBLE);
    if(!fy.getText().toString().isEmpty())
        image_fy.setVisibility(View.VISIBLE);
    if(!nAs.getText().toString().isEmpty())
        image_nAs.setVisibility(View.VISIBLE);
    if(!ds.getText().toString().isEmpty())
        image_ds.setVisibility(View.VISIBLE);
    if(!cover.getText().toString().isEmpty())
        image_cover.setVisibility(View.VISIBLE);
    if(!ffy.getText().toString().isEmpty())
        image_ffy.setVisibility(View.VISIBLE);
    if(!nAAs.getText().toString().isEmpty())
        image_nAAs.setVisibility(View.VISIBLE);
    if(!dds.getText().toString().isEmpty())
        image_dds.setVisibility(View.VISIBLE);

it doesn't depend on what I write in my EditText for example:

b.setText("0");
if(b.getText().toString().equals("0"))
        image_b.setVisibility(View.VISIBLE);

image_b is still invisible!

farshid83
  • 91
  • 1
  • 12
  • You need to be able to listen for changes in the editText to be able to do this. I would suggest adding a TextWatcher to each editText and moving the conditionals into the overridden afterTextChanged() within the TextWatcher. – kimchibooty Oct 11 '16 at 20:41
  • amazing..that worked tnx buddy – farshid83 Oct 12 '16 at 06:23
  • but I have anoter problem. I want when user click on edit text (for example b) and put a value imageview apper and when click on anither edittext (for example b) that image View disappear – farshid83 Oct 12 '16 at 06:36

0 Answers0