Stack Exchange
android fragment sqlite how to fetch all data
android fragment unable to display sqlite data in listview below is my code . i dont understand what i am doing wrong.
public class WindowsFragment extends ListFragment {
@SuppressWarnings("null")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    /** Creating array adapter to set data in listview */

    ArrayList<ContactListItems> contactList = new ArrayList<ContactListItems>();
    contactList.clear();
    String query = "SELECT * FROM PHONE_CONTACTS ";
    Cursor c1 = SqlHandler.selectQuery(query);
    if (c1 != null && c1.getCount() != 0) {
        if (c1.moveToFirst()) {
            do {
                ContactListItems contactListItems = new ContactListItems();

                contactListItems.setName(c1.getString(c1
                        .getColumnIndex("name")));

            } while (c1.moveToNext());
        }
    }
    c1.close();

    ContactListAdapter contactListAdapter = new ContactListAdapter(
            getActivity(), contactList);


    ListView simple_list_item_multiple_choice = null;
    simple_list_item_multiple_choice.setAdapter(contactListAdapter);

    return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onStart() {
    super.onStart();

    /** Setting the multiselect choice mode for the listview */
    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}

and below is my list adapter`public class ContactListAdapter extends BaseAdapter {
Context context;
ArrayList<ContactListItems> contactList;

public ContactListAdapter(Context context, ArrayList<ContactListItems> list) {

    this.context = context;
    contactList = list;
}

@Override
public int getCount() {

    return contactList.size();
}

@Override
public Object getItem(int position) {

    return contactList.get(position);
}

@Override
public long getItemId(int position) {

    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup arg2) {
    ContactListItems contactListItems = contactList.get(position);

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.contact_list_row, null);

    }

    TextView tvName = (TextView) convertView.findViewById(R.id.tv_name);
    tvName.setText(contactListItems.getName());
    TextView tvPhone = (TextView) convertView.findViewById(R.id.tv_phone);
    tvPhone.setText(contactListItems.getPhone());

    return convertView;
}

}
i am able to successfully run using activity but not working with fragment

You are not inserting values into contactlist array. contactList is empty when passed to listviewadapter.
Adding the line will solve your problem, it will insert ContactListItems object into the Arraylist.
contactList.add(contactListItems);
Code as below:
if (c1 != null && c1.getCount() != 0) {
    if (c1.moveToFirst()) {
        do {
            ContactListItems contactListItems = new ContactListItems();

            contactListItems.setName(c1.getString(c1
                    .getColumnIndex("name")));
              contactList.add(contactListItems);

        } while (c1.moveToNext());
    }
}
c1.close();

Also in your listview code, I dont see you are displaying the values.

In here:
if (c1 != null && c1.getCount() != 0) {
    if (c1.moveToFirst()) {
        do {
            ContactListItems contactListItems = new ContactListItems();

            contactListItems.setName(c1.getString(c1
                    .getColumnIndex("name")));

        } while (c1.moveToNext());
    }
}

You don't add anything to your contactList.
Also, I'd use Query method of SQLiteDatabase instead of raw String queries: 
public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit) 

from http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
Just set table and columns to tablename and new String[] {"name"}, everything else to null to select every name from table.
