First you need to have 3 image to switch for their state
def.png
disable.png
press.png
Now you need to have button_selector.xml
main.xml
ButtonStateExample.java
package monstercodz.blogspot.com; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class ButtonstateExample extends Activity implements OnClickListener { private Button btn1; private Button btn2; private boolean checkClick = false; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn1 = (Button)findViewById(R.id.btn); btn2 = (Button)findViewById(R.id.btn1); btn1.setOnClickListener(this); btn2.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == btn1){ Toast.makeText(getApplicationContext(), "Button Enable You can click", Toast.LENGTH_LONG).show(); }else{ if(!checkClick){ checkClick = true; btn1.setEnabled(false); }else{ checkClick = false; btn1.setEnabled(true); } } } }
you can also download Source codeClick here
0 comments:
Post a Comment