title: How to use findViewById in fragment and ArrayList cannot be applied - Android
body: <p>I have had to change a class from it being classed as a activity to a fragment and I don't know how I would set this up now as it now says that it cannot resolve the method on my findViewById. Any extra code can be given if required. Thanks for helping.</p>
  
  <pre><code>public class CustomizedListView extends Fragment {
  // All static variables
  static final String URL = "http://api.androidhive.info/music/music.xml";
  // XML node keys
  static final String KEY_SONG = "song"; // parent node
  static final String KEY_ID = "id";
  static final String KEY_TITLE = "title";
  static final String KEY_ARTIST = "artist";
  static final String KEY_DURATION = "duration";
  static final String KEY_THUMB_URL = "thumb_url";
  
  ListView list;
  LazyAdapter adapter;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle      savedInstanceState){
      return inflater.inflate(R.layout.main, container, false);
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; songsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      XMLParser parser = new XMLParser();
      String xml = parser.getXmlFromUrl(URL); // getting XML from URL
      Document doc = parser.getDomElement(xml); // getting DOM element
  
      NodeList nl = doc.getElementsByTagName(KEY_SONG);
      // looping through all song nodes &lt;song&gt;
      for (int i = 0; i &lt; nl.getLength(); i++) {
          // creating new HashMap
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          Element e = (Element) nl.item(i);
          // adding each child node to HashMap key =&gt; value
          map.put(KEY_ID, parser.getValue(e, KEY_ID));
          map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
          map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
          map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
          map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));
  
          // adding HashList to ArrayList
          songsList.add(map);
      }
  
  
      list=(ListView)findViewById(R.id.game_list);
  
      // Getting adapter by passing xml data ArrayList
      adapter=new LazyAdapter(this, songsList);
      list.setAdapter(adapter);
  
  
      // Click event for single list row
      list.setOnItemClickListener(new OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
  
  
          }
      });
  }
  }
  </code></pre>
  
  <p>This is what is causing me trouble with the findViewById because it cannot resolve the method:</p>
  
  <pre><code>list=(ListView)findViewById(R.id.game_list);
  </code></pre>
  
  <p>And this is what is causing me problems on the ArrayList and apparently it is because LazyAdapter (android.app.Activity, ArrayList>) in LazyAdapter cannot be applied to (com.example.app.CustomizedListView, ArrayList>)</p>
  
  <pre><code>        // Getting adapter by passing xml data ArrayList
      adapter=new LazyAdapter(this, songsList);
      list.setAdapter(adapter);
  </code></pre>
  
  <p>main.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="vertical"
  android:background="#e5e5e5" &gt;
  
  &lt;ListView
      android:id="@+id/game_list"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:divider="#e5e5e5"
      android:dividerHeight="6dp"
      android:background="#e5e5e5"
      android:layout_marginLeft="6dp"
      android:layout_marginRight="6dp"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>