Android Open Source - ExpertAndroid Create A Meaning Activity

From Project

Back to project page ExpertAndroid.


The source code is released under:

MIT License

If you think the Android project ExpertAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.androidbook.parse;
//w  w  w . j  a  v a  2 s . c  o m
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.parse.ParseException;
import com.parse.SaveCallback;

 * Given a word create a meaning for it.
 * uses layout: create_word_meaning (cwm_)
public class CreateAMeaningActivity 
extends FormActivity 
  TextView word;
  TextView wordDetail;
  EditText meaning;
  Word parceledWord;
  public CreateAMeaningActivity()  {

  public void onCreate(Bundle savedInstanceState) {
    parceledWord = getParceledWordFromIntent();
    //Make sure this is one ofthe last calls

  protected void initializeFormFields() 
    word = (TextView)findViewById(;
    wordDetail = (TextView)findViewById(;
    meaning = (EditText)findViewById(;
    //Only meaning is a required field
    addValidator(new Field(meaning));
    //initialize word
    word.setText("Provide meaning for:" + getWordText(parceledWord));
    //initalize wordDetail

  private String getWordText(Word pword)
    return pword.getWord();
  private String getWordDetail(Word pword)
    String by = pword.getCreatedByUser().username;
    Date d = pword.getCreatedAt();
    DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
    String datestring =  df.format(d);
    return by + "/" + datestring;
  private Word getParceledWordFromIntent()
    Intent i = this.getIntent();
    if (i == null)    {
      throw new RuntimeException("Sorry no intent found");
    //intent is available
    ParseObjectWrapper pow = 
    if (pow == null) {
      throw new RuntimeException("ParceledWord not found");
    Word parceledWord = new Word(pow);
    reportTransient("Parcelled word recovered");
    return parceledWord;
  public void createMeaning(View v)
    if (validateForm() == false)
    String meaning = getMeaning();
    //form is valid
    WordMeaning wm = new WordMeaning(meaning, parceledWord);
    turnOnProgressDialog("Saving Word Meaning", "We will be right back");
    wm.po.saveInBackground(new SaveCallback() {
      public void done(ParseException e) {
        if (e == null)  {
          //no exception
        else  {
  private String getMeaning()
    return this.meaning.getText().toString();
  private void wordMeaningSaveFailed(ParseException e)
    String error = e.getMessage();
    alert("Saving word failed", error);
  private void wordMeaningSavedSuccessfully()
    //Don't finish it as back button is valid
    alert("word meaning saved", "Success");

Java Source Code List