Create a new App to understand Fragment Concepts – Part 1

It’s time for you to start with a new App. We will call this one EmployeeApp

In this Video you will see how to create this App Project. In the coming Tutorial Posts you will learn about Back Stack, Fragment Communication, Fragment Transaction Manager and More.

So get started.

Source Code for this App :

Learn how to display a List of Items in a Fragment using ListFragment

You have seen how to use ListActivity to display a List of items in an Activity. Similar to that we have a ListFragment which can be used to display a List of items in a Fragment.

The advantages of using a ListFragment are:

  • You don’t have to create a Layout XML file. You can if you want.
  • You don’t have to create an EventListener.

To learn more please watch the Video.

Source Code available here

Android Basics – Learn about the FragmentManager and how to use it in an Activity

Now that you have created an Activity and a Fragment chances are that your Activity needs to talk to the Fragment.

Like your Activity may need to send the Fragment some data, say List ID. And using this ID the Fragment will display details.

To refer to a Fragment you cannot use the findViewById method.

In order to reference a Fragment in an Activity we use FragmentManager.

  • Step 1   Use getFragmentManager() which is available in your Activity class to get a reference to FragmentManager.
  • Step 2   Use getFragmentManager().findFragmentById() to get reference to the Fragment you need to use.

Follow the Video to learn more. You can view the Source Code here.

Android Basics – Learn about the Fragment Lifecycle

By now you should be familiar with the Activity Lifecycle looks like. If not don’t worry in this short video I will recap that also.

The Fragment Lifecycle is quite similar to the Activity Lifecycle. If you observe you will find that the Fragment has five more Lifecycle events.

The difference is at the time of Creation and when the Fragment gets destroyed.

How BarefootCollege is Solving India’s Electricity Problems

The ultimate solution for fighting poverty in India was not mass production but production by the masses – Mahatma Gandhi

We have to apply the Gandhian model to solar-electrifying villages – Bunker Roy

Bunker Roy is the Founder and Director of Barefoot College. His dream was to establish a Rural College in India that was built by and exclusively for the poor.

How Barefoot is trying to solve the Electricity Crisis in India

The School trains Barefoot Engineers – people from Rural areas who don’t get Electricity.

This is done using color-coded parts and hands-on lessons. After six months at the peaceful campus in the northwestern state of Rajasthan, the new technicians return to their home villages, bringing with them solar power equipment and know-how.

They’ll install solar panels, charging stations, and small LED lights in houses, and they’ll stand ready to deal with breakdowns.

While these systems offer only the most basic amenities of modern life, they also bring independence from India’s dysfunctional national power grid.

The Barefoot College began its pioneering work to bring off-grid solar power to India’s villages in the 1990s.

The program initially enrolled men, but these students proved disinclined to return to their villages once they had marketable skills.

When the school began recruiting grandmothers instead, the program took off. This very literal campaign of rural empowerment shows the untapped potential of women.

Despite being uneducated they have the skills and the intelligence.

You can read more about this initiative here

Barefoot College Website

Image Courtesy

Learn how to use a Fragment with an Activity

In the last Tutorial you learnt about Fragments and why to use them.

Using a Fragment with an Activity is pretty simple to start with. You need to add the fragment attribute to the activity layout file. Follow the short video to know how to do this.

Refer to the code here

Android Basics – Learn how to handle Clicks in a ListActivity using onListItemClick

By now you should be familiar with a ListActivity and how to use this to display items.

So what happen’s when a user clicks on an item. How can you handle that ?

The good news is that you don’t need to use an EventListener. You can simply override onListItemClick method.

public void onListItemClick(ListView listView, View itemView, int position, long id){
    //Implement your Logic
    //Here id param is id of the item clicked. It can also be the DB unique id

Source code is available here