# Supercharge your Android Application-1(The List).
Published: 2014-11-17
Updated: 2014-11-17
Canonical: https://prashamhtrivedi.in/supercharge-android-application-1.html
Series: Supercharge Apps
Tags: List, Deprecated
---
Developing android applications are lot easy if you **exactly** know which platform you are developing for. But for either one or other reasons we don't have time to leverage functionalities of our platforms to make our life easy. And as far as I can acknowledge it happens frequently with android. Breaking habits of traditional development (of web and of iOS) android has lot more bells and whistles that many of us don't know. Here, with this series, I am not talking about animations or anything fancy. I am talking about some bricks and mortar which should be applied properly at the foundations.
The apps many of us develop are having either some complex functionalities, or having some iOS functionalities which have easy replacements, but they are generally not acceptable because they do not belong to iOS. And above all the people who decide the timeline always *overestimate our power* (feel free to imagine **angry lord vader** here). Thus we are always in rush, without having time or knowledge of some awesome things that can make our life easy. Some of us who regularly see some top android developers' blog and/or Google+ profiles may be familiar with some or all of the tricks. But some are still learning and looking to solve their problems. If you are in the former, and have some new tricks, please share it with us. If you are later and looking for help, **these are the droids you are looking for**.
Before I start let me tell you one last thing, When I was building Wish 'N U as a demo of what I have been learning, I didn't know many of the tricks I am going to share with you, and as a result the app released on November 2013 was a laggy, slow and bit of unreliable. Fast forward to a year and I have managed to release the same app being fast, more (~70%) reliable and somehow looking beautiful. Having applied many of the tricks during development you will face many of the examples and codes related to the app.
Not talking too much let's start with our first trick.
## 1.When list is used, always use ListFragment. {#tip1}
Fragments are awesome things to use. Learning and mastering it is bit tricky, but when you get the mastery, you will feel proud. And one of the fragment I always tend to use is `ListFragment`. And I recommend you to choose ListFragment over normal ListViews, because it comes with a unique functionality: **Untill you set an adapter to it, it will always show default progressbar.** Thus you don't have to care about showing `ProgressBar` or `ProgressDialog` everytime you are loading a list.
It helps in numerous cases, when you are getting some data from remote server, loading local contacts or doing complex calculation before showing it on list. It takes time, and in normal case, either we show a progress dialog with Please wait or we use framelayout to show an inline progressbar with manually hide and unhide progressbars and list as per our needs.
If you use `ListFragment` instead of normal list view, you don't have to manage progressbars on your own, List fragment does it for you.
AsyncTask<Params, Progress, Result> task = new AsyncTask<Params, Progress, Result>() {
@Override
protected Result doInBackground(Params... params) {
//DO YOUR BACKGROUND WORK HERE
}
@Override
protected void onPostExecute(Result model) {
super.onPostExecute(models);
adapter = new Adapter();
setListAdapter(adapter);
}
}public static SpannableString getEmptyMessage(Resources resources, String message, int color) {
String string = new StringBuilder().append(" ").append("\n").append("\n").append(message).toString();
SpannableString ss = new SpannableString(string);
Drawable icon = resources.getDrawable(R.drawable.ic_launcher);
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
ImageSpan span = new ImageSpan(icon, DynamicDrawableSpan.ALIGN_BOTTOM);
ForegroundColorSpan colorSPan = new ForegroundColorSpan(color);
ss.setSpan(span, 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
ss.setSpan(colorSPan, 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan(18,true);
ss.setSpan(sizeSpan, 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return ss;
} SpannableString ss = getEmptyMessage(getResources(), message, color);
setEmptyText(ss);