Note that there are some explanatory texts on larger screens.

plurals
  1. POIn Android programming, how do you change the image of the button after being clicked?
    primarykey
    data
    text
    <p>I just want to set a button's image to change when clicked. Example, if I want to click button A it will change. If I click button B, its image will change and the image of button A will revert back. How can I do this? I badly need help on this one. </p> <pre><code>package com.example.mobile_nurse; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.Window; import android.widget.ImageButton; public class Posture_1 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.activity_posture_1); Back(); _1minute(); _15minute(); } private void _15minute() { ImageButton Button1 = (ImageButton) findViewById(R.id.imageButton3); ImageButton Button4 = (ImageButton) findViewById(R.id.imageButton4); View.OnClickListener myListener = new View.OnClickListener() { @Override public void onClick(View v) { Button1.setBackgroundResource(R.drawable.posms1_button1_null); Button4.setBackgroundResource(R.drawable.posms1_button_a); } }; Button1.setOnClickListener(myListener); } private void _1minute() { ImageButton Button1 = (ImageButton) findViewById(R.id.imageButton3); ImageButton Button4 = (ImageButton) findViewById(R.id.imageButton4); View.OnClickListener myListener = new View.OnClickListener() { @Override public void onClick(View v) { Button1.setBackgroundResource(R.drawable.posms1_button1); Button4.setBackgroundResource(R.drawable.posms1_button_a_null); } }; Button1.setOnClickListener(myListener); } private void Back() { ImageButton Button = (ImageButton) findViewById(R.id.imageButton1); View.OnClickListener myListener = new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }; Button.setOnClickListener(myListener); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.posture_1, menu); return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload