title: Android ListView with Fragment
body: <p>I'm working on my school project which is based on a Fragment. I have made the XML files but I'm getting an error in the nearfragment.java. Could you please tell me where the error is as I'm familiar with Activity but not with Fragment. Please help me to rectify the error.</p>
  
  <p>near_layout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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="{relativePackage}.${activityClass}" &gt;
  
      &lt;ListView
          android:id="@+id/list_li"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true" &gt;
      &lt;/ListView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>near_layout_mylist.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal" &gt;
  
      &lt;ImageView
          android:id="@+id/icon_list"
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:padding="5dp" /&gt;
  
      &lt;LinearLayout android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;TextView
              android:id="@+id/item_list"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Medium Text"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:layout_marginLeft="10dp"
              android:layout_marginTop="5dp"
              android:padding="2dp"
              android:textColor="#33CC33" /&gt;
          &lt;TextView
              android:id="@+id/textView1_list"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="TextView"
              android:layout_marginLeft="10dp"/&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>CustomListNearAdapter.java</p>
  
  <pre><code>import android.app.Activity;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class CustomListNearAdapter extends ArrayAdapter&lt;String&gt; {
  
      private final Activity context;
      private final String[] itemname;
      private final Integer[] imgid;
  
      public CustomListNearAdapter(Activity context, String[] itemname, Integer[] imgid) {
          super(context, R.layout.near_layout_mylist, itemname);
          // TODO Auto-generated constructor stub
  
          this.context=context;
          this.itemname=itemname;
          this.imgid=imgid;
      }
  
      public View getView(int position,View view,ViewGroup parent) {
          LayoutInflater inflater=context.getLayoutInflater();
          View rowView=inflater.inflate(R.layout.near_layout_mylist, null,true);
  
          TextView txtTitle = (TextView) rowView.findViewById(R.id.item_list);
          ImageView imageView = (ImageView) rowView.findViewById(R.id.icon_list);
          TextView extratxt = (TextView) rowView.findViewById(R.id.textView1_list);
  
          txtTitle.setText(itemname[position]);
          imageView.setImageResource(imgid[position]);
          extratxt.setText("Description "+itemname[position]);
          return rowView;
  
      };
  }
  </code></pre>
  
  <p>NearFragment</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.GridView;
  import android.widget.ListView;
  
  /**
   * Created by Ratan on 7/29/2015.
   */
  public class NearFragment extends Fragment {
  
  
  
      ListView list;
      String[] itemname ={
              "Safari",
              "Camera",
              "Global",
              "FireFox",
              "UC Browser",
              "Android Folder",
              "VLC Player",
              "Cold War"
      };
  
      Integer[] imgid={
              R.drawable.akash,
              R.drawable.akash,
              R.drawable.akash,
              R.drawable.akash,
              R.drawable.akash,
              R.drawable.akash,
              R.drawable.akash,
              R.drawable.akash,
      };
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          View view = inflater.inflate(R.layout.near_layout, container,false);
          CustomListNearAdapter adapter=new CustomListNearAdapter(this, itemname, imgid);
  
          ListView listView = (ListView) view.findViewById(R.id.list_item);
          listView.setAdapter(new CustomListNearAdapter(getActivity()));
          return view;
  
  
      }
  
  
  }
  </code></pre>
  
  <p>The error lies in nearfragment, I'm not able to write the code for the Fragment. So please give me some directions.</p>