use of android.view.View.OnClickListener in project coursera-android by aporter.
the class ButtonActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get a reference to the Press Me Button
final Button button = (Button) findViewById(R.id.button);
// Set an OnClickListener on this Button
// Called each time the user clicks the Button
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Maintain a count of user presses
// Display count as text on the Button
button.setText("Got Pressed:" + ++count);
}
});
}
use of android.view.View.OnClickListener in project coursera-android by aporter.
the class CheckBoxActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get a reference to the CheckBox
final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
// Set an OnClickListener on the CheckBox
checkbox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Set CheckBox text accordingly
if (checkbox.isChecked()) {
checkbox.setText("I'm checked");
} else {
checkbox.setText("I'm not checked");
}
}
});
// Get a reference to the Hide CheckBox Button
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Set the Button text accordingly
if (checkbox.isShown()) {
checkbox.setVisibility(View.INVISIBLE);
button.setText("Unhide CheckBox");
} else {
checkbox.setVisibility(View.VISIBLE);
button.setText("Hide CheckBox");
}
}
});
}
use of android.view.View.OnClickListener in project coursera-android by aporter.
the class RelativeLayoutActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText textEntry = (EditText) findViewById(R.id.entry);
final Button cancelButton = (Button) findViewById(R.id.cancel_button);
cancelButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Clear the textEntry
textEntry.setText("");
}
});
final Button okButton = (Button) findViewById(R.id.ok_button);
okButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Finish the application
RelativeLayoutActivity.this.finish();
}
});
}
use of android.view.View.OnClickListener in project coursera-android by aporter.
the class SamplerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//
final ImageButton button = (ImageButton) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Show Toast message
Toast.makeText(SamplerActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
final EditText edittext = (EditText) findViewById(R.id.edittext);
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "Done" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Show Toast message
Toast.makeText(SamplerActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Show Toast message indicating the CheckBox's Checked state
if (((CheckBox) v).isChecked()) {
Toast.makeText(SamplerActivity.this, "CheckBox checked", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SamplerActivity.this, "CheckBox not checked", Toast.LENGTH_SHORT).show();
}
}
});
final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
radio_red.setOnClickListener(radio_listener);
radio_blue.setOnClickListener(radio_listener);
final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
togglebutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
if (togglebutton.isChecked()) {
Toast.makeText(SamplerActivity.this, "ToggleButton checked", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SamplerActivity.this, "ToggleButton not checked", Toast.LENGTH_SHORT).show();
}
}
});
final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
Toast.makeText(SamplerActivity.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
}
});
}
use of android.view.View.OnClickListener in project coursera-android by aporter.
the class NetworkingAndroidHttpClientActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTextView = (TextView) findViewById(R.id.textView1);
final Button loadButton = (Button) findViewById(R.id.button1);
loadButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new HttpGetTask().execute();
}
});
}
Aggregations