How to make Views with an Invisible attribute 'Visible' after clicking a button

后端 未结 4 602
感动是毒
感动是毒 2021-01-26 03:52

I have several Views, text views, and a button that have the android:visibility=\"invisible\" attribute. My goal is to click a button that resides above these \'invisible\' widg

相关标签:
4条回答
  • 2021-01-26 04:21
    Button submitRating = (Button) findViewById(R.id.submitRatingButton);
            submitRating.setOnClickListener(new View.onClickListener)
            {
                 @Override
             public void onClick(View v) 
                {
                                  //Insert your code here
                        }
            }
    
    0 讨论(0)
  • 2021-01-26 04:25
    findViewById(R.id.ratingBar3).setVisibility(View.VISIBLE);
    findViewById(R.id.saveContinueButton3).setVisibility(View.VISIBLE);
    

    you made it invisible view invisible again.. try the above code

    0 讨论(0)
  • 2021-01-26 04:29

    Try

    public class VisibilityActivity extends Activity {
    
    private TextView mText;
    private View mRule1, mRule2;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_property3);
    
        mText= (TextView)findViewById(R.id.horizontalRule1);
        mRule1 = findViewById(R.id.TextView03);
        mRule2 = findViewById(R.id.horizontalRule2);
    
        Button submitRating = (Button) findViewById(R.id.submitRatingButton);
    
        submitRating.setOnClickListener(mVisibleListener);
    
    }
    
    OnClickListener mVisibleListener = new OnClickListener() {
        public void onClick(View v) {
            mText.setVisibility(View.VISIBLE);
            mRule1.setVisibility(View.VISIBLE);
            mRule2.setVisibility(View.VISIBLE);
        }
    };
    
    }
    
    0 讨论(0)
  • 2021-01-26 04:32

    I am updating user936414's answer.

    OnClickListener mVisibleListener = new OnClickListener() {
        public void onClick(View v) {
    
            if( mText.getVisibility() == View.INVISIBLE )
                mText.setVisibility(View.VISIBLE);
            else
                mText.setVisibility(View.INVISIBLE);
    
            if( mRule1.getVisibility() == View.INVISIBLE )
                mRule1.setVisibility(View.VISIBLE);
            else
                mRule1.setVisibility(View.INVISIBLE);
    
            if( mRule2.getVisibility() == View.INVISIBLE )
                mRule2.setVisibility(View.VISIBLE);
            else
                mRule2.setVisibility(View.INVISIBLE);
        }
    };
    

    Also you might want to experiment with View.GONE.

    0 讨论(0)
提交回复
热议问题