Sunday 21 December 2014

Android Quickies

With the amount of free time I "apparently" have on my hands, I have finally been able to dabble more into android programming. This blog will be a collection of some short lines which I have found useful.

Updating an ArrayAdapter for a list view


            ArrayList newData = new ArrayList(Arrays.asList(jsonString));
            myData.clear();
            myData.addAll(newData);
            myArrayAdapter.notifyDataSetChanged();
And that takes care of that!


ACTION BAR IN SETTINGS ACTIVITY

Typically, Settings activity extends a Preference Activity. However, for easy addition of the action bar, activities extend the ActionBar activity. You cannot extend more than one class in Java which means that if you are using the Preference activity method you will have to find a hack to hook up the action bar to your Settings activity. There a few workarounds.

If you are targeting android 3.0 and above (quite frankly, I see very little reason why you would be targeting anything less) then you should use PreferenceFragments and attach it to an activity which extends ActionBar activity. A description is given here in the android Docs.

If you are still bent on supporting other devices,..., well I have not figured that out yet. When I do will let you know. If you have please do post a comment.

No comments:

Post a Comment