Sunday, February 14, 2016

Android Multiple Event Handling Java

In this tutorial I will show you how to handle multiple events in Java for Android Development.

We will use a button and use their onClick and OnLongClick events to change the value of TextView


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(R.id.btnequal);  
6:      btn.setOnClickListener(new Button.OnClickListener(){  
7:        public void onClick(View v){  
8:          btnonClick();  
9:        }  
10:      });  
11:      btn.setOnLongClickListener(new Button.OnLongClickListener(){  
12:        public boolean onLongClick(View c){  
13:          longClick();  
14:          return true;  
15:        }  
16:      });  
17:    }  
18:    public void longClick(){  
19:      TextView txt = (TextView)findViewById( R.id.txtans) ;  
20:      txt.setText("That was a long click");  
21:    }  
22:  public void btnonClick(){  
23:    TextView txt = (TextView) findViewById(R.id.txtans);  
24:    txt.setText("Dont touch me");  
25:  }  


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

No comments:

Post a Comment