How to toggle background image on button click?

前端 未结 4 1004
无人及你
无人及你 2021-01-26 04:54

I have this code:

button1.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
          


        
4条回答
  •  青春惊慌失措
    2021-01-26 05:24

    if xml as the following

        
    
            


    handling Code will be like

    
    public void switchToListView(View view) {
        (Button) findViewById(R.id.btnListView).setVisibility(View.GONE);
        (Button) findViewById(R.id.btnGridView).setVisibility(View.VISIBLE);
    }
    public void switchToGridView(View view) {
        (Button) findViewById(R.id.btnGridView).setVisibility(View.GONE);
        (Button) findViewById(R.id.btnListView).setVisibility(View.VISIBLE);
    
    }
    
    
    

提交回复
热议问题