Sunday, January 29, 2012

Android: Personal Dictionary App

It helps you to create your own dictionary.
So at the beginning you have to add words and its translations, and after that, you can consult the stored words, modify or delete (selecting the word).
 I think that It is very helpful when arriving to a new country, or when learning new languages because you can store for example the ingredients at the beginning, and when going to a restaurant you can consult the meaning really quickly.

 it's free!

When learning a new language, one of the most important things is the vocabulary.

It is important to have a tool where write new words to learn. A place where you can consult and modify, when needed.

My Personal Dictionary is the tool that will help you when learning new languages.

With Personal Dictionary you can:
Add new words
Search stored words
Modify stored words
Delete stored words

https://market.android.com/details?id=personalDictionary.vmrvictor

Android: creating and fullfilling a list

Sometimes, It is needed to update a list of elements, for example for an agenda, a list of things to buy, etc.


For create a list we have to add to our xml layout the following:

<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
  android:layout_height="wrap_content" >
</ListView>


and we can add entries by using code, for example the action fillData(), will take our own objects, in my case words and add them to the list by using an adapter.

private void fillData() {
     //db.open(); open the database
     words = db.fetchAllWords();
     ArrayAdapter<Word> adapter= new ArrayAdapter<Word>(this, R.layout.entry, R.id.text1, words);
    ListView lv = getListView();
    lv.setAdapter(adapter);
    //db.close();
}



your own objects, in my case Word needs to have overriten the toString method, the string that will be returned is the string used by the adapter, so the string which will be used for fullfill the list.

@Override
public String toString(){
     return a+" -> "+b;
}

Android: Updating values when returning from another activity

The problem that I had was that when returning from an activity the list was not getting update until a keyEvent was realized.

For example, the main activity contain a list of strings that gets from a database, It is updated by using the action FillData(), and I had an activity for add new elements to the database, and another for modify or delete.

The problem was that when creating/adding/modifying the values at one of the other activities and finishing this activies (returning to the main activity) the list was not updated with the new values.

The solution of this problem is to Overrite the onResume() event, looking at the graph of http://developer.android.com/reference/android/app/Activity.html that when the event is Paused, later on is called the onResume event.

For example in my case:

@Override
public void onResume(){
      super.onResume();
      EditText searchTextField=(EditText) findViewById(R.id.searchTextField);
      fillData(searchTextField.getText());
}

I get the value from an EditText field getting the filter to use when filling the list and later call to fillData that fullfills the list.