Monthly Archives: March 2015

Getting warning when calling getView() in Fragment

if you are getting below warning from compiler in your class where you are trying to create Fragment instance;

Warning: Method invocation ‘getView().findViewById(R.id.test)’ may produce ‘java.lang.NullPointerException’

Then chances are you are inflating your layout in onCreateView and trying to access layout elements outside that method.
Continue reading Getting warning when calling getView() in Fragment

Android: setting width and height programatically

There are times when you need to change width and height of View elements you defined in your XML layout or you want to create elements dynamically.
In that case you need to grab the view element and changed its layoutParams. Like how it is done below:

LinearLayout layout = (LinearLayout)findViewById(R.id.layoutId);
ViewGroup.LayoutParams params = layout.getLayoutParams();
params.width = 200;
params.height = 200;
layout.setLayoutParams(params);

Continue reading Android: setting width and height programatically

Keeping leading zeros in Microsoft Excel

There are situations where you need leading zero in your data. For instance, product codes (SKU) or ZIP codes.
For example, when copy and pasting “0800” into Excel, it will be converted to “800”.
That’s because when you copy and paste this data into Microsoft Excel, by default Excel tries to parse the value according to that cells format. Therefore, Excel recognizes data as numeric and strip out the leading zero.
Continue reading Keeping leading zeros in Microsoft Excel

Fetching data from a CSV file using PHP

To open a CSV file, start by opening the file by using PHP function fopen.

After opening the file (creating file pointer), cycle through the content using fgetcsv function. This function reads the file line by line and parse it based on fields in CSV.

Continue reading Fetching data from a CSV file using PHP