forked from sushanacharya/myAPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Option5Activity.java
60 lines (51 loc) · 1.84 KB
/
Option5Activity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.example.navadroid.androidonclickevent;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
// TODO: View.OnClickListener as inner class
public class Option5Activity extends AppCompatActivity {
private EditText etInput;
private TextView tvOutput;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_option5);
bindView();
initView();
}
// To bind views to this activity
private void bindView(){
etInput = (EditText) findViewById(R.id.et_input_5);
tvOutput = (TextView) findViewById(R.id.tv_body_5);
}
private void initView(){
// To register click event to view
findViewById(R.id.btn_process_5).setOnClickListener(new InnerOnClickListener());
}
// A class that handles all of click events
// It is private from other android class since it is within the Activity.
class InnerOnClickListener implements View.OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_process_5:
greet();
break;
}
hideKeyboardInput(v);
}
}
// To greet the user
private void greet(){
tvOutput.setText(getString(R.string.greeting) + " " + etInput.getText().toString());
}
// To hide Android soft keyboard
private void hideKeyboardInput(View v){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}