"Pustin" listView



  • ListView listView = (ListView)container.findViewById(R.id.listView);
    ViewGroup rootView = (ViewGroup)inflater.inflate(R.layout.fragment_one, container, false);
    String[] datasource = {"aaaa", "bbbb", "cccc"};
    final ArrayAdapter<String> adapter;
    adapter = new ArrayAdapter<String>(getActivity(), R.layout.simple_list_item_1, R.id.text1, datasource);
    listView.setAdapter(adapter);
    

    When I start the app, there's a mistake. java.lang.NullPointerException in line listView.setAdapter(adapter);

    Here's the xml fragment on which ListView

    <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"
    android:orientation="vertical"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    tools:context="com.andrew.mpd.fragments.OneFragment">

    <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    &lt;ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listView" /&gt;
    

    </ScrollView>

    What did I miss or do wrong?



  • ViewGroup rootView = (ViewGroup)inflater.inflate(R.layout.fragment_one, container, false);
    ListView listView = (ListView)rootView .findViewById(R.id.listView);
    

    And never turn ListView into ScrollView.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2