Skip to content

Instantly share code, notes, and snippets.

@wowiwo1
Last active September 16, 2015 07:20
Show Gist options
  • Save wowiwo1/9330a38d1d083d3ff482 to your computer and use it in GitHub Desktop.
Save wowiwo1/9330a38d1d083d3ff482 to your computer and use it in GitHub Desktop.
public class MainActivity extends Activity {
final static int USER_EVENT = 1000;
Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnMakeEvent = (Button) findViewById(R.id.btn);
final EditText etInput = (EditText) findViewById(R.id.et);
final TextView tvOutput = (TextView) findViewById(R.id.tv);
btnMakeEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message msg = handler.obtainMessage();
msg.what = USER_EVENT;
msg.obj = etInput.getText().toString();
handler.sendMessage(msg); // Message.obtain(handler, MYEVENT);
}
});
handler = new Handler() {
public void handleMessage(Message msg) {
switch(msg.what) {
case USER_EVENT:
tvOutput.setText((String)msg.obj);
break;
}
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment