In this article we will create an Android application which will display the “HelloFragment” using a fragment.
1. Create a new Android project namely “HelloFragmentNew”
2. Select build target
3. Enter application details
4. res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, MainActivity!</string> <string name="app_name">HelloFragment</string> </resources>
5. res/layout/hello_fragment_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="@string/app_name" /> </LinearLayout>
6. src/in/wptrafficanalyzer/hellofragmentnew/HelloFragment.java
package in.wptrafficanalyzer.hellofragmentnew; import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class HelloFragment extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { View v = inflater.inflate(R.layout.hello_fragment_layout, null); return v; } }
7. res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <fragment android:id="@+id/hellofragment" android:name="in.wptrafficanalyzer.hellofragmentnew.HelloFragment" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
8. Application in execution
9. Download

10. Reference
http://developer.android.com/guide/index.html

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in
You can hire me on hourly basis or on project basis for Android applications development.
For hiring me, please mail your requirements to info@wptrafficanalyzer.in.
My other blogs
store4js.blogspot.com