Adapter(6)SimpleCursorAdapter示例

1.SimpleCursorAdapterFrgmt.java

public class SimpleCursorAdapterFrgmt extends Fragment {
    private ListAdapter  adapter;
    private ListView lv;
    
    private void init() {
        Cursor cur = getActivity().getContentResolver().query(
                People.CONTENT_URI, null, null, null, null);
        getActivity().startManagingCursor(cur);
        
        adapter = new SimpleCursorAdapter(getActivity(),
                android.R.layout.simple_list_item_1, cur,
                new String[] { People.NAME }, new int[] { android.R.id.text1 });
        
        lv.setAdapter(adapter);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.frgmt_simple_cursor_adapter, container,
                false);
        lv = (ListView) v.findViewById(R.id.simple_cursor_adapter_list_view);
        init();
        return v;
    }
}

2.frgmt_simple_cursor_adapter.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/simple_cursor_adapter_list_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >
    </ListView>

</LinearLayout>

 

posted @ 2015-05-26 11:15  f9q  阅读(132)  评论(0)    收藏  举报