title: Cursor adapter and SQLite solution with Fragments
body: <p>I am a very novice Android developer and am working on a very simple application that reads entries from SQLite database and maps them to a ListView, displaying the CUSTOMER_NAME field, whenever the 'List All' button is clicked.  I have been following a bunch of different tutorials but have been running into scope issues. </p>
  
  <p><strong>Edit:</strong>: How do I proceed with finishing the mapping from cursor to ListView? </p>
  
  <p>Any help you can provide is much appreciated!</p>
  
  <p>So far my DBHelper, getAllCustomer method looks like: </p>
  
  <pre><code>public Cursor getAllCustomers(){
      List&lt;Customer&gt; customers=new LinkedList&lt;Customer&gt;();
  
      String query="SELECT * FROM "+TABLE_NAME;
  
      SQLiteDatabase db=this.getWritableDatabase();
      Cursor cursor= db.rawQuery(query, null);
  
      return cursor;
  }
  </code></pre>
  
  <p>My fragment_list.xml looks like (see ListView): </p>
  
  <pre><code>&lt;LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:text="List Customers"
          android:id="@+id/textView3"
          android:layout_gravity="center_horizontal" /&gt;
  
      &lt;ListView
          android:layout_width="wrap_content"
          android:layout_height="381dp"
          android:layout_centerHorizontal="true"
          android:layout_alignParentTop="true"
          android:id="@+id/listView"
          android:layout_above="@+id/btnAdd" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="List All"
          android:id="@+id/btnGetAll"
          android:layout_alignParentBottom="true"
          android:layout_toRightOf="@+id/btnAdd" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And finally my CustomersFragment.java</p>
  
  <pre><code>public class CustomersFragment extends Fragment {
  
  public CustomersFragment() {
  
  }
  
  public static CustomersFragment newInstance() {
      CustomersFragment fragment = new CustomersFragment();
      Bundle args = new Bundle();
      fragment.setArguments(args);
      return fragment;
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_search, container, false);
      return rootView;
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
  
      Button bGetAll = (Button) getActivity().findViewById(R.id.btnGetAll);
      bGetAll.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              CustomerrDBSetup db = new CustomerrDBSetup(getActivity());
              Cursor cursor = db.getAllCustomers();
              String[] from = new String[] { "customer_name" };
  
          }
      });
    }
  }
  </code></pre>