Thursday, 8 December 2011

Android - Why not use alert dialog instead of spinner?

Spinner in android is more confusing to use. It is also hard to customize it for our needs. Based on the purpose, a simple alert dialog could be used as a replacement for spinner.
In my requirement, I had a button. When the button is clicked, the options should be listed. Based on the selected options, the value of the button is set.
Here is the code for the above requirement.

In the Xml, define the button layout.
<Button
android:id="@+id/annualButton1"
        android:layout_width="50dp"
        android:layout_height="40dp"
        android:layout_toRightOf="@id/totincome"
        android:layout_marginLeft ="10dp"
        android:layout_marginRight="5dp"
        android:layout_alignTop="@id/totincome"
        android:background="@android:drawable/btn_default"
        android:textSize="15dp"/>


In the code, alert dialog is called when the button is clicked.  Based on the option selected, button value is set.

annualButton1.setOnClickListener(new OnClickListener()
{
              public void onClick(View v)
              {
                    sButtonClicked = "button1";
                    showSpinner();
                                   
                }
        });
 
 
protected void showSpinner()
    {
            AlertDialog.Builder b = new Builder(this);
            String[] options = {sItem1,sItem2};
                 
            b.setTitle("Select an option" );
                  b.setSingleChoiceItems(options, -1,new DialogInterface.OnClickListener(){
                        public void onClick(DialogInterface dialog, int which)
                        {
 
                     dialog.dismiss();
                     switch(which){
                     case 0:
                     {
                           annualButton.setText("p.a");;
                           sAnnual = sItem1;
                         break;
                     }
                     case 1:
                     {
                           annualButton.setText("p.m");
                           sAnnual = sItem2;
                         break;
                     }
                                 
                 }}
 
                        });
                  b.setPositiveButton("CANCEL", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                   
                      dialog.dismiss();
                
                      }
             });
                 
                 
                  b.show();}
          
It is much simpler than using a spinner. Isn’t it?

Android - Generic declaration of colours


It is very important that we declare background colours and layouts generically. I made this mistake of hardcoding the colours in the individual xml files. It became really hectic every time I wanted to try different colours. Then finally, I decided to declare them generically. Here is how you do it.

Declare mycustomcolors.xml in the values folder. Define all the colour codes here.


<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="bgcolor">#F8F8F8</color>
<color name="headtxtcolor">#e69b28</color>
<color name="othertxtcolor">#000000</color>
<color name="headerEnd">#999999</color>
<color name="headerStart">#000000</color>
<color name="profileEnd">#E69B28</color>
<color name="profileStart">#FFAE33</color>
<color name="sectionEnd">#FFFFFF</color>
<color name="sectionStart">#CCCCCC</color>
</resources>

   
The above colour codes can be used in shapes and other layouts. This is for a gradient colour button profile_band.xml in drawable-hdpi. 

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<gradient
    android:startColor="@color/profileStart"
    android:endColor="@color/profileEnd"    
    android:angle="90" /> 
    
</shape>
Text colours used in an xml..

 <TextView
        android:id="@+id/profName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/header"
        android:paddingLeft="10dp"
        android:text="profile name"
        android:textColor="@color/othertxtcolor"
        android:textSize="14dp"
        android:layout_gravity="center_vertical"
       />


As mobile apps should have good screen appearance , it is very important that you have the flexibility to try various options.

Saturday, 22 October 2011

Financial Planning for your child’s future

Your child’s future is more important than yours. Is that an overstatement?

Traditionally, at least in India, savings is always like remitting money into a bank deposit account, on a regular basis, which earns interest, e.g., recurring deposit. A slightly neo-financial model is to start an insurance policy or a PPF account. As the insurance industry got reformed a few years back, ULIPs became more prominent and the more favoured vehicle for savings by the agents/brokers. But is this model working? Not that much, as the yield is very low, due to which many parents take various unregulated modes of savings, e.g., unregulated chit funds. These unregulated savings vehicles cannot be trusted and there is a huge risk in losing the capital.

As we grow more matured and much informed than our parents in this information age, we need to go for a well designed financial strategy to save for our child’s future. Savings/Investing for the child’s future is a bit different from other savings goals as there is a need to pull out money at designated points of time to fund the child’s needs, say at the age of 13/14, we may need more money to put them in the right training courses to enable them to land in the right academic institution. At 16/17, we may need another packet for their university degree. Again at their age of 20/21 we may need yet another packet for their higher education/training/job. This goes on till they get settled in a job and start a family. The various age periods and approximate costs parents may incur are in the below table.


Age



Purpose



Amount
(approx.)



3-4



Starting Primary
School



Rs. 1 to 2 lakhs



9-10



Starting High School



Rs. 2 to 3 lakhs
(optional)



13-14



Training courses to
enter their university of their choice



Rs. 1 to 2 lakhs



16-17



Join University



Rs. 3 to 5 lakhs



21-22



Joining a job



Rs. 1 to 2 lakhs



21-22



Starting a company



Anywhere between 10 to
50 lakhs



25-30



Marriage



As per your/your kid’s
wish




The amounts in the above table may look a bit high. I had inflated them to account to some extent the inflation by the time your child reaches that age. Also, the last but one in the table on "Starting a company", may not be the case for every parent. But it is better to build a kitty, if possible. :-)

To satisfy each of those milestones in those stipulated time frames, we need to take a pragmatic approach – a dynamic portfolio that can churn out the required sum of money at the required time. But that needs an actively managed portfolio, for which most of the parents neither have the time nor the patience. Hence the best option will be to run separate portfolios for each of those milestones.

As with any investment portfolio, child savings too should be a combination of equity and debt instruments. For milestones that are closer to the current, as market swings may push the portfolio to any extreme, Debt instruments should occupy a major portion – say 80%-90%. The ones that are farther by years, equity exposure should be as high as possible as markets tend to provide far greater returns than debt instruments in the long run. Now let’s re-visit the milestones and their favourable portfolio mix.


Age



Purpose



Amount
(approx.)



Equity
: Debt



3-4



Starting Primary
School



Rs. 1 to 2 lakhs



0% : 100%



9-10



Starting High School



Rs. 2 to 3 lakhs
(optional)



30% : 70%



13-14



Training courses to
enter their university of their choice



Rs. 1 to 2 lakhs



50% : 50%



16-17



Join University



Rs. 3 to 5 lakhs



70% : 30%



21-22



Joining a job



Rs. 1 to 2 lakhs



80% : 20%



21-22



Starting a company



Anywhere between 10 to
50 lakhs



90% : 10%



25-30



Marriage



Anywhere between 5 to
10 lakhs



90%:10%



Favourable equity instruments are stocks, mutual funds and ETFs. In case of debt instruments, NSC and PPF provide tax savings, and are suitable for long term goals. If you are looking for 2-3 years then Recurring deposit is a better deal.

Also, the equity to debt ratios have to be reviewed at least on a yearly basis and adjusted based on the years left to complete. For e.g., the portfolio related to join university has an equity to debt ratio of 70%:30%. However if that milestone will be reached in the next 3 years, one has to keep an eye on the market and try to sell off some stocks/units at the right market situation to reduce the equity exposure and move that money into debt instruments. When the milestone is reached, almost all the money has to be in debt instruments.

Now to the question that would be lingering in your mind by now. Won’t an ULIP or a Child insurance plan simplify all these? My advice would be – “Beware of such plans and avoid them as much as possible”. Why?
  • One, most of these insurance plans do not return money at the right time, as in the above table.
  • Two, the yield will be less. Endowment child savings policies normally return a meager 3%-4% yield. ULIPs eat most of your investment in terms of charges and again the returns would be much lesser when compared to the above method.
If you are worried about your child’s future, in case of any adverse situation, anyway at those situations, your portfolios will be returned to your nominee and a cheap insurance term plan will be able to provide the cover required to your family and kids. That's the right way to do that. Never mix insurance with investment.