Skip to content

Instantly share code, notes, and snippets.

@basilbeltran
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basilbeltran/5d7ff9f8e0765bed0393 to your computer and use it in GitHub Desktop.
Save basilbeltran/5d7ff9f8e0765bed0393 to your computer and use it in GitHub Desktop.
various view listeners
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_m, parent, false);
//Button
mButton = (Button) v.findViewById(R.id.data_date);
mButton.setText(object.getDate().toString()); // mDateButton.setEnabled(false);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
//EditText
mEditText = (EditText) v.findViewById(R.id.object_title);
mEditText.setText(object.getTitle());
mEditText.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence c, int start, int before, int count) {
object.setTitle(c.toString());
}
public void beforeTextChanged(CharSequence c, int start, int count, int after) {}
public void afterTextChanged(Editable c) {}
});
//CheckBox
mCheckBox = (CheckBox)v.findViewById(R.id.object_whatever);
mCheckBox.setChecked(object.isWhatever());
mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
object.setWhatever(isChecked); }
});
//DatePicker
DatePicker dpView = (DatePicker)getActivity().getLayoutInflater().inflate(R.layout.dialog_date, null);
mDate = (Date)getArguments().getSerializable(EXTRA_DATE);
Calendar cal = Calendar.getInstance(); cal.setTime(mDate);
dpView.init(cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH),
new DatePicker.OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year, int month, int day) {
mDate = new GregorianCalendar(year, month, day).getTime();
getArguments().putSerializable(EXTRA_DATE, mDate);
}
}
); //dpView.init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment