Sunday, February 14, 2016

Android Event Handling Java

Hello everyone, in this tutorial I will show you how to implement event handling in Java for Android Development.

The example I will provide will include two controls a button and a TextView.

When user click the the button the value of textView will change.

1:   protected void onCreate(Bundle savedInstanceState) {  
2:      super.onCreate(savedInstanceState);  
3:      setContentView(R.layout.activity_main);  
4:      client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();  
5:      Button btn = (Button) findViewById(;  
6:      btn.setOnClickListener(new Button.OnClickListener(){  
7:        public void onClick(View v){  
8:          btnonClick();  
9:        }  
10:      });  
11:    }  
12:  public void btnonClick(){  
13:    TextView txt = (TextView) findViewById(;  
14:    txt.setText("Dont touch me");  
15:  }  

I hope that it was informative for you and I would like to Thank you for reading

No comments:

Post a Comment