<h3><span style="color: #000080;"><strong>ListFragment</strong></span></h3>
<p>A fragment that displays a list of items by binding to a data source such as an <strong><span style="color: #008000;">array or Cursor</span></strong>, and exposes event handlers when the user selects an item.</p>
<p>The basic implementation of <strong><span style="color: #008000;">list fragment</span></strong> is for creating list of items in fragments.</p>
<p>Get <strong><span style="color: #0000ff;">GITHUB</span></strong> code from <span style="color: #0000ff;"><a style="color: #0000ff;" href="https://github.com/arunk7839/ListFragmentExp"><strong>Here</strong></a>.</span></p>
<p><amp-youtube layout="responsive" width="1200" height="675" data-videoid="Yzi9HUtgcbQ" title="Android ListFragment Example"><a placeholder href="https://youtu.be/Yzi9HUtgcbQ"><img src="https://i.ytimg.com/vi/Yzi9HUtgcbQ/hqdefault.jpg" layout="fill" object-fit="cover" alt="Android ListFragment Example"></a></amp-youtube></p>
<p> ;</p>
<p><span style="color: #008000;"><strong>Let&#8217;s have a look at the simple example of android ListFragment.</strong></span></p>
<p><strong><span style="color: #0000ff;">activity_main.xml</span></strong></p>
<p><code></code></p>
<pre><strong><;?xml version="1.0" encoding="utf-8"?>;
<;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.example.lenovo.listfragmentapp.MainActivity">;

 <;FrameLayout
 android:id="@+id/frame_layout"
 class="com.example.lenovo.listfragmentapp.FragmentA"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 />;

<;/RelativeLayout>;</strong>
</pre>
<p><strong><span style="color: #0000ff;">fragment1.xml</span></strong></p>
<p><code></code></p>
<pre><strong><;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.example.lenovo.listfragmentapp.FragmentA">;


 <;ListView
 android:id="@id/android:list"
 android:layout_width="match_parent"
 android:layout_height="match_parent">;

 <;/ListView>;

<;/LinearLayout>;</strong>
</pre>
<p><strong><span style="color: #0000ff;">MainActivity.Java</span></strong></p>
<!-- WP QUADS Content Ad Plugin v. 2.0.98.1 -->
<div class="quads-location quads-ad2" id="quads-ad2" style="float:none;margin:0px;">

</div>

<p><code></code></p>
<pre><strong>package com.example.lenovo.listfragmentapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 FragmentA fragment1 = new FragmentA();
 getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, fragment1).commit();
 }

}</strong>

</pre>
<p><strong><span style="color: #0000ff;">Fragment1.Java</span></strong></p>
<p><code></code></p>
<pre><strong>package com.example.lenovo.listfragmentapp;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class Fragment1 extends ListFragment {

 String[] code_name = {"Froyo", "GingerBread", "HoneyComb", "IceCream Sandwich", "JellyBean", "Kitkat", "Lollipop", "Marshmallow", "Nougat", "Oreo"};


 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

 View view = inflater.inflate(R.layout.fragment1, container, false);
 ArrayAdapter<;String>; adapter = new ArrayAdapter<;String>;(inflater.getContext(), android.R.layout.simple_list_item_1, code_name);
 setListAdapter(adapter);
 return view;

 }

 @Override
 public void onListItemClick(ListView l, View v, int position, long id) {
 Toast.makeText(getActivity().getBaseContext(), code_name[position], Toast.LENGTH_SHORT).show();
 }
}
</strong>
</pre>
<p><strong><span style="color: #0000ff;">When you run the app it will look like this:</span></strong></p>
<p><strong><span style="color: #0000ff;"><img class="aligncenter wp-image-220 size-full" src="https://c1ctech.com/wp-content/uploads/2018/03/Screenshot_2018-03-13-18-47-171.png" alt="" width="480" height="800" /> </span></strong>

